HELP! * GREY=local LOCAL HTML version of Foils prepared 15 January 1997

Foil 37 The eval JavaScript Function

From JavaScript Tutorial for CPS616 Technologies of the Information Age 1997 Basic Information Track of CPS -- Spring Semester 97. by Geoffrey C. Fox * Important Information in IMAGE
Addon
eval is an important function as it allows you build Javascript dynamically
For instance document.forms[0].actualtextname.value is value of form element specified as
<INPUT TYPE="text" NAME="actualtextname" VALUE="value" onChange="handle(this.name)" >
this.name holds actualtextname but as an ascii string which cannot be directly be used in
var x = document.forms[0].actualtextname.value;
var x = eval("document.forms[0]." + actualtextname + ".value"); // works!
eval applies JavaScript interpreter to argument and then re-interprets as shown above
This can be used to copy information between forms as in
eval("document.forms[1]." + actualtextname + ".defaultvalue") = eval("document.forms[0]." + actualtextname + ".value")
eval did not work properly for a long time! -- Please check on your browser



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 Feb 19 1997