Forum Moderators: open

Message Too Old, No Replies

'Eval' problem

How to tick checkbox by using eval method

         

tmcat

4:52 am on Dec 5, 2003 (gmt 0)

10+ Year Member



I got 3 chkbox with the name 'chkbox0', 'chkbox1' and 'chkbox2'. So for some reason i need to use the following code to 'tick' these 3 checkbox but i don't know what's wrong with my code and it cannot function.
my code is as below

___________________________________________________
var max=2;

for(i=0; i<=max; i++){
eval("document.form.chkbox"+i+".checked=true");
}
____________________________________________________

when i clicked the errormsg on window status bar, it showed me 'Object expected'. So what should i do to solve this problem? Please help me~~

Thanks

DrDoc

5:18 am on Dec 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World!

Have you tried:

for(i=0; i<=max; i++){
foobar = 'chkbox' + i;
document.form.foobar.checked=true;
}

or...

for(i=0; i<=max; i++){
if(document.getElementById) {
document.getElementById('chkbox'+i].checked=true;
}
else if(document.all) {
document.all['chkbox'+i].checked=true;
}
}

dcrombie

11:54 am on Dec 5, 2003 (gmt 0)



document.form.elements["chkbox"+i].checked=true;

tmcat

8:28 am on Dec 8, 2003 (gmt 0)

10+ Year Member



To Dr.Doc: I tried both of your suggestions already but it seem like does not function and cannot solve the problem. Anyway thanks for your help. ^_^

The solutions suggested by dcrombie can work!
The problem is solved.

Thanks a lot.