[Javascript] dynamically creating variables using eval() SOLVED

Lau lau at goldenweb.com.au
Thu Aug 23 04:12:37 CDT 2001


innerHTMLFor those who are interested I solved the problem by first creating an object "varlist" and then dynamically adding properties to the object.

<html><head>
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
var varlist = new Object(Object);
// -->
</SCRIPT>
</head><body>
<A HREF=# onclick='Javascript:eval("varlist.prototype.newvar=11");'>create variable "newvar"</A><BR>
<A HREF=# onclick='Javascript:alert("varlist.newvar="+varlist.newvar);'>view  "newvar"</A>
</body></html>


regards
Lau
  ----- Original Message ----- 
  From: Lau 
  To: javascript at LaTech.edu 
  Sent: Thursday, August 23, 2001 6:06 PM
  Subject: [Javascript] dynamically creating variables using eval()


  Hi 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/25bd17b1/attachment.htm>


More information about the Javascript mailing list