Check or uncheck all checkboxes by checking a checkbox
Option 1
Option 2
Option 3
Option 4
Option 5
Controller
Here is the HTML:
<form name="formname">
<input type="checkbox" name="checkboxname">Option 1<br>
<input type="checkbox" name="checkboxname">Option 2<br>
<input type="checkbox" name="checkboxname">Option 3<br>
<input type="checkbox" name="checkboxname">Option 4<br>
<input type="checkbox" name="checkboxname">Option 5<br>
<input type="checkbox" name="checkboxname" onclick="checkthem(document.formname.checkboxname);">Controller
</form>
Here is the Javascript:
<script type="text/javascript">
var checkboxes = 5; //The number of checkboxes
var controller = checkboxes; //0 if the controller checkbox is the first one, the checkboxes number if it`s the last one
function checkthem(form){
      if(form[controller].checked == true){
            for(var i=0;i<checkboxes;i++){
                  form[i].checked = true;
            }
      }
      else{
            for(var i=0;i<checkboxes;i++){
                  form[i].checked = false;
            }
      }
}
</script>

0 comments:

Post a Comment