Return to Snippet

Revision: 8251
at September 10, 2008 20:41 by aristoworks


Initial Code
<script language="JavaScript">
		function checkAll(theForm, cName, status) {
		for (i=0,n=theForm.elements.length;i<n;i++)
		  if (theForm.elements[i].className.indexOf(cName) !=-1) {
		    theForm.elements[i].checked = status;
		  }
		}
		</script>

		<form id="selectForm">

		Set 1:
		<br>
		<input type="checkbox" name="selected" value="01" class="results1"><br>
		<input type="checkbox" name="selected" value="02" class="results1"><br>
		Select All/None <input type="checkbox" onclick="checkAll(document.getElementById('selectForm'), 'results1', this.checked);" />
		<br>
		<br>

		Set 2:
		<br>
		<input type="checkbox" name="selected" value="01" class="results2"><br>
		<input type="checkbox" name="selected" value="02" class="results2"><br>
		Select All/None <input type="checkbox" onclick="checkAll(document.getElementById('selectForm'), 'results2', this.checked);" />

		</form>

Initial URL
http://www.customcmssolutions.com

Initial Description
This is a simple javascript snippet that will allow you to specify a particular class to a group of checkboxes and then select them all at once when you click the master checkbox.  This came in very handy for a store inventory script when I needed to select all of the models of a particular manufacturer.

Initial Title
Select All Checkboxes Based On Class

Initial Tags
javascript, class

Initial Language
JavaScript