...

View Full Version : Declaring a global variable inside a funtion



OhLordy
10-01-2003, 02:55 PM
Hi, is there any way to declare a global variable from inside a function? It needs to be created in the onload = function() {} but then I also need to be able to use it around my page.
Thanks in advance
Rob

Exodious
10-01-2003, 03:09 PM
But you could declare the variable before the onload and let the function change its value...


Any reason(s) why you don't want to declare it first?

OhLordy
10-01-2003, 03:18 PM
LOL!! I was being an idiot. I was declaring it inside and instantiating it as an object of a class that I'd made. Every time I took the declaration/instantiation outside the onload function it all went silly.
You were, absolutely right. I just needed to take the declaration outside and leave the instantiation on the inside.
All working lovely now :D :D
ThAnK YoU VeRy mUcH !1!
Rob

liorean
10-01-2003, 03:25 PM
Or you could assign it as a child of the window object. That also makes it global.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum