Custom Search : Technical Guides Sybase Oracle UNIX Javascript

Technical Guides

Of Interest

Business Intelligence and Analytics

Oracle Training

Javascript » Methods » Coding »

Executing Dynamic Code


Javascript statement blocks can be created and executed using the eval
function. This is similar to dBase's macro prefix. The eval function
takes an argument as a string- this string can be a line of code, or a
variable, or any piece of Javascript that could execute in the given
context. Here is an example:

 var myvar1=0
 var myvar2=0
 var myvar3=0
 /* set all variables to 100 */
 for (i=1;i<4;i++) {
           eval("myvar" + i + "=100");
Here is another example, in which a function calls one of four different functions based on the parameter:
 function f_sort(parm1)
 eval("array1.sort(f_compare" + parm1 + ");");
 eval("prev1=loc" + parm1 + "1;");
 eval("prev1=loc" + parm1 + "2;");
Using the eval function saved 9 lines of code in this case!.

Javascript : Related Topics

Javascript : Methods : Incrementing a counter within an edit field
Javascript : Methods : Animation Example
Javascript : Methods : Image Mapping Example
Javascript : Methods : Redirecting Page Access
Javascript : Methods : Loading a new page dynamically
Javascript : Methods : Complex Application with Forms
Javascript : Methods : Image Viewer with Prev and Next Buttons
Javascript : Methods : Array Processing, Frameset Writes
Javascript : Methods : Javascript: Where it fits in HTML
Javascript : Methods : Accessing the cookie file
Javascript : Methods : Using include files
Javascript : Methods : Pure virtual call error
Javascript : Methods : Passing variables to windows
Javascript : Methods : Single line edit: Data entry issue
Javascript : Methods : Call CGI counter
Javascript : Methods : Dynamic Objects and Names
Javascript : Methods : Setting Focus to a Control During Load

Sybase Web Site
Sybase iAnywhere Mobile Web Site
Oracle Enterprise Web Site

Get the latest Rocket99 news and tech tips via

Site Index About this Guide to Sybase, Oracle, and UNIX Contact Us Advertise on this site

Copyright © 2016 Stoltenbar Inc All Rights Reserved.