JavaScript Check / Uncheck All Functionality

Posted on January 04, 2008
The following JavaScript will check all / uncheck all elements on the page.
function checkAll (obj) {
  var arrInput = document.getElementsByTagName("input");
  for (i=0; i<arrInput.length; i++) {
    if (arrInput[i].type == 'checkbox') {
      arrInput[i].checked = obj.checked;
    }
  }
}

Instead of multiple functions, the above code simply toggles all checkboxes.

Drop this into your html view:
<input type="checkbox" name="check_all" id="check_all" value="" onchange="checkAll(this);" /> Select / De-select All

And you have Select All / De-select all functionality.