[thelist] javscript variables question - easy one

Chris.Marsh at Callserve.com Chris.Marsh at Callserve.com
Thu Feb 10 07:42:05 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.

I found this interesting:

<http://c2.com/cgi/wiki?GlobalVariablesAreBad>

Regards

Chris Marsh 

_______________________________________________________________________
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender and delete the email immediately. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited. 

Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company.

Finally, the recipient should check this email and any attachments for the presence of viruses. Callserve Communications accepts no liability for any damage caused by any virus transmitted by this email. _______________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service.


More information about the thelist mailing list