[Javascript] Re: dynamically creating variables using eval()

Lewis Shadoff lshadoff at brazosport.cc.tx.us
Thu Aug 23 07:37:26 CDT 2001


At 07:26 AM 8/23/01, you wrote:
>How can I dynamically create a new javascript variable that will be 
>available to subsequent scripts.
>I can use eval("var newvar;newvar=3D33;") to create the variable, but the 
>new variable only seems to exist within the scope of the script block that 
>it was created in. Below is a page that demonstrates what I mean... the 
>first alert works, the second one says that newvar is undefined.

In IE, variables created within a function are local variables.  In order 
to create a global variable it must be defined at the root level.  This is 
not the case in Netscape where all variables are global no matter where 
they are created.

I suggest you create a number of dummy global variables in your original 
code and then assign them on-the-fly.


Lewis A. Shadoff, PhD
Brazosport College
Lake Jackson, TX




More information about the Javascript mailing list