View Full Version : Declaring a global variable inside a funtion

10-01-2003, 03: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

10-01-2003, 04: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?

10-01-2003, 04: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!

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