I am having two functions in my JavaScript code, and I want to perform some action on the basis of value returned by other function.
Here my code :-
function test1(){
var radio = document.getElementByName('sample');
for (i=0; i<radio.length; i++){
//some code here
return "some value on basis of above code"
}
}
function test2(){
var somevariable = globllysetValue;
var returnValue = return test1();
// some code and work according to the value in returnValue
}
Well I know return in function test2 is not correct. so what can I do here NOW????
Edit
Here what I am Trying to do… but it do not seem to be working
http://jsfiddle.net/U6RjY/7/
EDIT2 —– The corrected and working fiddle… http://jsfiddle.net/U6RjY/9/
Thanks to all 🙂
Just remove the return.
You will notice however that in function test1, it will return the value on the first loop. So, it will stop executing.
Live example: http://jsfiddle.net/U6RjY/