I have oftentimes found it very useful to create a master checkbox that will check all checkboxes in a form if checked. After a little research and doing it a few times I have found two examples that work quite well.
My first example doesn't need to know the form name and will take in a variable which will tell it whether or not to check or uncheck the checkboxes. The value passed in to this function is either 'check' or 'uncheck'. To call the function below I use the following code:
<input type="checkbox" name="checkall" onClick="if(this.checked){checkallboxes('check');} else { checkallboxes('uncheck'); }">
<script language="javascript">
function checkallboxes(type){
ips=document.getElementsByTagName('INPUT');
for (i=0;i<ips.length;i++){
if( type == 'check'){
if (ips[i].type=='checkbox'){
ips[i].checked = true;
}
} else {
if (ips[i].type=='checkbox'){
ips[i].checked = false;
}
}
}
}
</script>
Another script that I have used for the same goal is listed below. The code to call this function is: <input type="checkbox" name="checkall" onClick="if(this.checked){checkAll(document.myform.product_ids);} else { uncheckAll(document.myform.product_ids); }">
<script language="javascript">
function checkAll(field){
for (i = 0; i < field.length; i++){
field[i].checked = true ;
}
return true;
}
function uncheckAll(field){
for (i = 0; i < field.length; i++){
field[i].checked = false ;
}
}
</script>