[thelist] javascript variable issue (continued)

Hassan Schroeder hassan at webtuitive.com
Fri Aug 31 10:28:47 CDT 2001


ALBIE ATTIAS wrote:

> As you can see, it now almost works. The only snag is that the first three
> variables always seem to be undefined. I've tried to work out why but I
> can't spot it. 

I'd replace the superfluous eval statement ...

/* old */

       eval("document.forms['quiz']." + argname + ".value=" + thisValue + ";");

/* new */

	document.forms['quiz'].elements[argname].value = thisValue;

This works on a copy of your page I made. It's much cleaner (more 
readable, more maintainable) code.

/*
   A comment on eval():
 
   Using eval as above takes actual objects and treats their name(s) 
   as a string - in order to be evaluated as objects. What's the point?

   YMMV! :-)
 */ 
-- 
H*
Hassan Schroeder ----------------------------- hassan at webtuitive.com 
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

    -- creating dynamic Web sites and applications since 1994 --




More information about the thelist mailing list