Welcome to WebmasterWorld Guest from 3.214.184.196

Forum Moderators: open

Message Too Old, No Replies

'Eval' problem

How to tick checkbox by using eval method

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

New User

10+ Year Member

joined:Dec 5, 2003
posts:2
votes: 0


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

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

Senior Member

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 15, 2002
posts:6807
votes: 0


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)

Inactive Member
Account Expired

 
 


document.form.elements["chkbox"+i].checked=true;
8:28 am on Dec 8, 2003 (gmt 0)

New User

10+ Year Member

joined:Dec 5, 2003
posts:2
votes: 0


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.