[Javascript] dynamically creating variables using eval()

Lau lau at goldenweb.com.au
Thu Aug 23 03:06:53 CDT 2001


innerHTMLHi all,

How can I dynamically create a new javascript variable that will be available to subsequent scripts.
I can use eval("var newvar;newvar=33;") 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.

<html><head></head><body>
<A HREF=# onclick='Javascript:eval("var newvar;newvar=33;");alert(newvar);'>create variable "newvar"</A><BR>
<A HREF=# onclick='Javascript:alert("newvar="+newvar);'>view  "newvar"</A>
</body></html>

Thanks in advance
Lau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20010823/cea1ffee/attachment.htm>


More information about the Javascript mailing list