HELP! * YELLOW=global GREY=local Global HTML version of Foils prepared 21 February 97

Foil 25 The eval JavaScript Function

From Feb 17/19 Delivered Lecture for Course CPS616 -- aJavaScript Language Objects and Frames CPS616 spring 1997 -- Feb 17 and 19 1997. by Geoffrey Fox * Important Information in IMAGE
Secs 205.9 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 Fri Feb 21 1997