[thelist] javscript variables question - easy one

Kasimir K evolt at kasimir-k.fi
Thu Feb 10 07:23:36 CST 2005


Brian Delaney / 2005-02-09 17:50
> so I declared global variables: globalStart globalEnd
> I pass these to datecheck datecheck(globalStart, globalEnd) from the 
> main function main()
> 
> if both fields are not = NULL then I assign:
> 
> globalStart = globaStart + form.txtStartdate.value
> globalEnd = globalEnd + form.txtEnddate.value
> 
> If i use the alert() to display the value of  these in the datecheck() 
> they are correct.
> 
> If i use the alert() in the main() calling function they display NULL - 
> blank values.

There is no need to pass the variables like this:
datecheck(globalStart, globalEnd);
as they are already available for the function (they are global).
Just call:
datecheck();
and manipulate globalStart and globalEnd there.

If you define your function like this:
function datecheck(globalStart, globalEnd)
then you declare two local variables (globalStart and globalEnd) for 
that function, and as they have the same names as global variables, the 
function has no access to those global variables, only to local.


.k



More information about the thelist mailing list