Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return onclick value to a JavaScript function

I have created an anchor with an onclick event which calls a JavaScript function. The JavaScript function returns some value. I want to use that value in another JS function.

e.g loading() will return some value which will get passed to another js function. How do I capture and store the return value, and then pass this value to that function?

like image 678
Ganesh Avatar asked Aug 28 '26 02:08

Ganesh


1 Answers

Can you simply call the outer function with the inner function?

function outerFunc(a)
{
  alert(a);
}

function innerFunc()
{
  return 'test';
}

onclick="outerFunc(innerFunc());"

Or, if you need to use the return value in another event, set a variable.

var retval;
function outerFunc()
{
  if(retval) alert(retval);
}

function innerFunc()
{
  retval = 'test';
  return retval;
}

onclick="return innerFunc();"

In someother onclick event

onclick="return outerFunc();"
like image 174
Chris Gessler Avatar answered Aug 29 '26 16:08

Chris Gessler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!