Our blog
Javascript Toggle Checkboxes
I seem to use this little snippet loads so I thought I would post it up for safe keeping:
Toggling all checkboxes on a page:
-
<script type="text/javascript">
-
function toggleCheckboxes() {
-
// written by Daniel P 3/21/07
-
// toggle all checkboxes found on the page
-
var inputlist = document.getElementsByTagName("input");
-
for (i = 0; i <inputlist.length; i++) {
-
if ( inputlist[i].getAttribute("type") == 'checkbox' ) { // look only at input elements that are checkboxes
-
if (inputlist[i].checked) inputlist[i].checked = false
-
else inputlist[i].checked = true;
-
}
-
}
-
}
-
</script>
-
<button onClick="toggleCheckboxes();">Toggle Enabled Fields</button>
I can't remember where I first found it. If you know where it originates please feel free to add a link in the comments
More Reading:
One Comments
|
I don't know if you were first since you don't date your blog but I searched based on togglecheckboxes and Daniel P and found the only other link on the GOOG with the same signature: http://snipplr.com/view/2407/toggle-all-form-checkboxes/ |
RSS Feed
Joe Mamma
July 23rd, 2010