Check / uncheck all checkboxes in a form

One easy JavaScript function that will check or uncheck all the checkboxes in a form that's being passed as the first argument to the function.
  1. // To check all: CheckUncheckAll(‘myFormId’, true);
  2. // To uncheck all: CheckUncheckAll(‘myFormId’, false);
  3. function CheckUncheckAll(formID, checkAll)
  4. {
  5.  var currForm = document.getElementById(formID);
  6.  for (var i = 0; i < currForm.elements.length; i++)
  7.  {
  8.                 currForm.elements[i].checked = checkAll;
  9.  }
  10. }

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top