[thelist] Javascript Help

Joshua Olson joshua at waetech.com
Wed Apr 10 09:07:01 CDT 2002


----- Original Message -----
From: "Feingold Josh S" <Josh.S.Feingold at irs.gov>
Sent: Wednesday, April 10, 2002 9:34 AM
Subject: RE: [thelist] Javascript Help


> Thanks, that worked.  Can you explain why mine didn't?

Josh,

Sure.  In your code you are simply constructing a string literal and trying
to assign a variable to it.

"document.br." + name + ".value" = newstring

This syntax works in some languages, ColdFusion is one I think, but won't
work in most languages.  Anytime you wrap a variable name in quotes you are
constructing a string.  JS does have a function called eval that can help
with what you are trying to do:

eval("document.br." + name + ".value = '" + newstring + "'");

In this example you are constructing a string and dynamically evaluating the
string like it was a block of code.  99.9% of the times you will not need to
use eval, though.  Usually, there is an approach using brackets that will
work; and, the bracket notation is generally a lot easier to read.  :)

Hope this help,
-joshua





More information about the thelist mailing list