Click to See Complete Forum and Search --> : javascript eval problem - should be easy


adumas
02-03-2003, 02:45 PM
I can not seem to get this code to work correctly...

If i hardcode the element name in the first alert, it works.
If i try to pass the variable, it doesn't. What's wront with the syntax...

By the way, the variable references a form element that is a radio box and it has up to 4 values.


newchoice ="LittlePleasure";

// works
alert ("value hardcoded: " + eval(document.all.LittlePleasure[3].checked));

// doesn't work
alert ("value var passed: " + eval(document.all.newchoice[3].checked));

gil davis
02-03-2003, 03:25 PM
Do you mean "newchoice" is a string VAR that contains "LittlePleasure"? Try:

alert("value var passed: " + document.all[newchoice][3].checked);

You would be cross-browser compliant using:

alert("value var passed: " + document.formName[newchoice][3].checked);

(but then it would not surprise me to hear that you don't have a form tag, either).