I've created a recursive function to find the form in which an object sits inside of. my function is:
why will it alert the correct value in the first function, but no the second function?
Code:
function getParentForm(el){
var parent_ref;
if(el.parentNode.tagName != "FORM"){
getParentForm(el.parentNode);
} else {
if(el.parentNode.name){
parent_ref = el.parentNode.name;
} else {
parent_ref = el.parentNode.id;
}
}
alert(parent_ref); // this has the correct value in it
return parent_ref;
}
function otherFunction(elm){
parentForm = getParentForm(elm);
alert(parentForm); // does not alert the same as the alert above.
}
why will it alert the correct value in the first function, but no the second function?