eval stuff (was Re: [thelist] testing for empty in javascript or vbscript)

Shashank Tripathi sub at shanx.com
Mon Jul 15 22:18:06 CDT 2002


Hi,

Before I rant on with my lame defence, you may like to see this:
http://erudition.com/eval.gif

I knew MS was getting somewhere with their spellchecks!


> Danny Goodman is the author of the indispensible JavaScript Bible,
> 4th Edition, and an all around js guru guy.


Being a devout RTFM freak, I usually just read the netscape JS docs and
MSDN, which are both adequately detailed. But yes, I know the 'bible' is a
ragingly popular book. (Btw, "Who is DG" was a rhetorical question, the
answer to which for me was a google away...sorry if it sounded
inappropriate, popularity I guess is a relative thing... I mean I would be
equally surprised if someone in my vicinity asked me "Who is Shashank
Tripathi?")


> I code at work for IE only all the time, I NEVER use eval, especially
> for DHTML. Maybe its a learned thing - don't want to start a holy war
> here, but I still sit on the side that says don't use it.


Don't worry about the holy wars. :) I am learning all the time, including
right now..

Basically the app I was talking about was a pretty complex (almost
pseudo-software simply because they wanted a non-applet web version) client
side interface including trigonometric/math functions etc. It allowed users
to dynamically increase the number of rows of form inputs on their page.
Each dynamically generated row included 16 text boxes, 2 radiobuttons (for a
selection) and several checkboxes. All users are on 21 inch screens (for
good reason). The names for each of these elements were generated at
run-time.

We had to validate these forms on the client-side as well as the
server-side. Since the names of these form elements were generated at run
time including the number of the row etc, validating them on client side
needed their element name (e.g., document.calcForm.res12.value .... where
the X in resXY was the row, and the Y was the column of the input element).
The validation was dependent on the number of the row not just the element's
column, the rules for which came from an external "BusinessRules.ini"
file..which converted into JS functions at run-time.

Cannot go into more detail, but we covered several options for such
validation, including looping through the form elements etc, but that was
just bulkier given our requirements because of the rules for almost each
element.

I may look like I am scrambling to prove a point (well, and that would
partly be right! :)) but just giving you an example of a good case where
eval is pretty useful.

FWIW,  functions like eval() in server side languages are quite voted
against as well, but pretty useful sometimes. For instance, if you wish to
save your error messages etc in a separate config file, but want some
dynamic variable to be a part of that message during run time. A very
simplistic example..

    #IN A SEPARATE CONFIG FILE:
    $message = "Thanks for logging in, " . $userName;

One reason we have had to do this is in cases where the value of the
variable itself remains the same, but the text of the message needs to be
multilingual based on user login..

Btw, I hope the original issue with this thread is solved?

Guess I owe a tip?

-Shanx.



<tip type="virtual desktop/emulator software" author="Shashank Tripathi
shanx at shanx.com">

Apart from VMWare, you could also consider Connectix's Virtual PC. A cinch
to install, and quite fast in its renditions of the other OSes right on your
desktop.

http://connectix.com

</tip>




More information about the thelist mailing list