Check or Uncheck all Checkboxes

Submitted by:Andery Smith

Date added:20 August, 2014

Category:JavaScript

Javascript function to check or uncheck all the checkboxes in a form.

Tags: javascript function , checkboxes

Code Snippet:

FUNCTION SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
IF(!document.forms[FormName])
RETURN;
VAR objCheckBoxes = document.forms[FormName].elements[FieldName];
IF(!objCheckBoxes)
RETURN;
VAR countCheckBoxes = objCheckBoxes.length;
IF(!countCheckBoxes)
objCheckBoxes.checked = CheckValue;
ELSE
// set the check value for all check boxes
FOR(VAR i = 0; i < countCheckBoxes; i++)
objCheckBoxes[i].checked = CheckValue;
}
 
 

Comments