Click to See Complete Forum and Search --> : problem with variable declarations.


MadCommando
07-17-2003, 04:57 PM
here's a technical question.

I run one function declare a variable then run another function and the same variable is undefined.... why?

var secndsd=document.site.secndsd.value
alert(secndsd)
downr()
}

function downr()
{
alert(secndsd)
secndsd--
output.document.site.secndsdisp.value=Display(secndsd)
if(secndsd<=0){disp()}
else down=setTimeout("downr()",1000);
}

my first alert comes up as my input number, the second shows an error saying the variable is undefined. :confused:

Charles
07-17-2003, 05:05 PM
When you declair a variable inside of a function the variable is actually a property of the call object. It is only addressible by the function and is destroyed when the function returns. To make something that looks like a global variable omit the 'var' or address it directly as a property of the window object: window.secndsd=document.site.secndsd.value