Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] dynamically creating variables using eval()
- From: javascript@xxxxxxxxxx (Lau)
- Subject: [Javascript] dynamically creating variables using eval()
- Date: Thu, 23 Aug 2001 18:06:53 +1000
This is a multi-part message in MIME format.
------=_NextPart_000_0006_01C12BFE.634F1820
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
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=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.
<html><head></head><body>
<A HREF=3D# onclick=3D'Javascript:eval("var =
newvar;newvar=3D33;");alert(newvar);'>create variable "newvar"</A><BR>
<A HREF=3D# onclick=3D'Javascript:alert("newvar=3D"+newvar);'>view =
"newvar"</A>
</body></html>
Thanks in advance
Lau
------=_NextPart_000_0006_01C12BFE.634F1820
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>innerHTML</TITLE>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>How can I dynamically create a new =
javascript=20
variable that will be available to subsequent scripts.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I can use eval("var =
newvar;newvar=3D33;") to create=20
the variable, but the new variable only seems to exist within the scope =
of the=20
script block that it was created in. Below is a page that demonstrates =
what I=20
mean... the first alert works, the second one says that newvar is=20
undefined.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial=20
size=3D2><html><head></head><body><BR><A =
HREF=3D#=20
onclick=3D'Javascript:eval("var =
newvar;newvar=3D33;");alert(newvar);'>create=20
variable "newvar"</A><BR><BR><A HREF=3D#=20
onclick=3D'Javascript:alert("newvar=3D"+newvar);'>view =20
"newvar"</A><BR></body></html></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Thanks in advance</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Lau</FONT></DIV></BODY></HTML>
------=_NextPart_000_0006_01C12BFE.634F1820--
- Follow-Ups:
- References:
- [Javascript] innerHTML
- From: hormuz maloo
- [Javascript] innerHTML
- From: Lau
- [Javascript] innerHTML
- Prev by Date: [Javascript] innerHTML
- Next by Date: [Javascript] dynamically creating variables using eval() SOLVED
- Previous by thread: [Javascript] innerHTML
- Next by thread: [Javascript] dynamically creating variables using eval() SOLVED
- Index(es):