autumnnn
04-16-2004, 02:49 AM
hello,
I'm using this function to perform a "check all" action for checking all check boxes. The names of the checkboxes go like this:
test0
test1
test2
test3 ...
My script works really well but it breaks when the field name either starts with a number like:
5_test_it0
or if it has spaces like:
test it0
Can you please tell me how I can make it work? I can probably replace the spaces with underscores if I have to but I can't change the numbers.
function checkAll(t,f) {
// f is form name t is field name
for (var j = 0; j <= 100; j++) {
box = eval("document." +f+ "." +t + j);
mainbox = eval("document." +f+ "." +t);
if (mainbox.checked == false){
box.checked = false;
}else{
box.checked = true;
}
}
}
// check all checkbox
<input type="checkbox" name="5 page website" onclick="checkAll(this.name,'form1');" />
// the checkboxes
<input type="checkbox" name="5 page website0" value="yes" >
<input type="checkbox" name="5 page website1" value="yes" >
<input type="checkbox" name="5 page website2" value="yes" >
Thank you
A
I'm using this function to perform a "check all" action for checking all check boxes. The names of the checkboxes go like this:
test0
test1
test2
test3 ...
My script works really well but it breaks when the field name either starts with a number like:
5_test_it0
or if it has spaces like:
test it0
Can you please tell me how I can make it work? I can probably replace the spaces with underscores if I have to but I can't change the numbers.
function checkAll(t,f) {
// f is form name t is field name
for (var j = 0; j <= 100; j++) {
box = eval("document." +f+ "." +t + j);
mainbox = eval("document." +f+ "." +t);
if (mainbox.checked == false){
box.checked = false;
}else{
box.checked = true;
}
}
}
// check all checkbox
<input type="checkbox" name="5 page website" onclick="checkAll(this.name,'form1');" />
// the checkboxes
<input type="checkbox" name="5 page website0" value="yes" >
<input type="checkbox" name="5 page website1" value="yes" >
<input type="checkbox" name="5 page website2" value="yes" >
Thank you
A