/ Published in: JavaScript
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<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>
URL: http://www.customcmssolutions.com