sumawuscha
asked on
How to eval() dynamic object name with '-' in its name
Hello,
i use a form with a lot of checkboxes, which are generated dynamically. Every checkbox has its ID which comes from a database. These IDs can be positive or negative. Thus a checkbox can have a name like "mybox-2".
Sadly my JavaScript function has a problem with such names...
How can i tell the eval() function to evaluate '"document.formWithCheckbo xes.mybox" + boxID' as a String for negative boxIDs, too?
Thanks in advance!
i use a form with a lot of checkboxes, which are generated dynamically. Every checkbox has its ID which comes from a database. These IDs can be positive or negative. Thus a checkbox can have a name like "mybox-2".
Sadly my JavaScript function has a problem with such names...
How can i tell the eval() function to evaluate '"document.formWithCheckbo
Thanks in advance!
function swapAll(boxID) {
box = eval("document.formWithCheckboxes.mybox" + boxID);
box.checked = !box.checked;
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Right... I was looking at the Microsoft documentation, which specifies parentheses...
@GreenGhost - I have made the same mistake at least a few times as I switch from ASP/vbscript to Javascript and back. The MS document probably was using clientside vbscript which needs parentheses. Good suggestion to lose the eval() though unless it is needed for some reason we can't see. :)
bol
bol
box = document.formWithCheckboxe
Thanks for the grade, the points and the fun question.
bol