Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] Re: dynamically creating variables using eval()
- From: javascript@xxxxxxxxxx (Lewis Shadoff)
- Subject: [Javascript] Re: dynamically creating variables using eval()
- Date: Thu, 23 Aug 2001 07:37:26 -0500
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
- Prev by Date: [Javascript] innerHTML
- Next by Date: [Javascript] Calculate on demand...
- Previous by thread: [Javascript] innerHTML
- Next by thread: [Javascript] Calculate on demand...
- Index(es):