posted 20 years ago
Generally speaking, you have to loop through and check/unchek them
The trick there is to get your checkboxes pointers.
1. if all checkboxes to be checked have the same name, you can do
function setChecked(isChecked){
var arr = document.getElementsByName("checkboxesName");
for(var i=0;i<arr.length;i++){
arr[i].checked=isChecked;
}
}
2. Otherwise you can do:
function setChecked(isChecked){
var arr = document.form.elements;
for(var i=0;i<arr.length;i++){
if(isValid(arr[i]))arr[i].checked=isChecked;
}
}
function isValid(element){
return element.type="checkbox";
}
Function isValid could be more complicated, like checking that name starts with some preffix, or check className or id or value - it is all up to you.