Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  13] [ 5]  / answers: 1 / hits: 29904  / 12 Years ago, sat, april 7, 2012, 12:00:00

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?


More From » html

 Answers
527

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();

[#86378] Thursday, April 5, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
monetm

Total Points: 615
Total Questions: 103
Total Answers: 119

Location: Finland
Member since Fri, Oct 21, 2022
2 Years ago
;