I have a function that I call in another function. It returns a variable called “checked”, but that name is not global, and is only within the scope of that function.
My other function has its own local variable called ‘checked’, but when I try set it to 1 it always returns 0.
I found that if I remove the function call to my first function it then gets the correct value.
How can this be when the scope of both variables is local to the function they are in?
function filterRadioCheck()
{
checked = 0;
$('#filterType').children('input').each(function() {
if ($(this).attr('checked'))
{
checked = $(this).attr('value');
}
});
return checked;
}
function setTagDefaultMode()
{
checked = 1;
radiocheck = filterRadioCheck();
//******'checked' is always 0 after this point*****///
// alert(checked) will return 0 even though checked it is set to 1 above;
}
The variable “checked” is global, because you forgot the
varkeyword.