Basic HTML version of Foils prepared 23 June 1997

Foil 37 The eval Function

From JavaScript Tutorial for Certificate Course UC Web applications Certificate -- Summer 97. by Geoffrey C. Fox, Tom Scavo

eval method
1 eval is an important function that lets you evaluate JavaScript code on-the-fly
2 For instance, document.forms[0].myName.value is the value of a form element:
3 <INPUT TYPE="text" NAME="myName" VALUE="value" onChange="handle(this.name)">
4 this.name holds myName as an ASCII string:
5 var x = document.forms[0].myName.value; // No!
6 var s = "document.forms[0]." + myName + ".value";
7 var x = eval(s); // Yes!
8 That is, eval applies the JavaScript interpreter to its argument
9 This can be used to copy information between forms as in
10 eval("document.forms[1]." + myName + ".defaultvalue")
11 = eval("document.forms[0]." + myName + ".value")
12 For a long time, eval didn't work right, so check your browser!

in Table To:


Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Apr 1 1998