Toggle all form checkboxes


/ Published in: JavaScript
Save to your folder(s)

Simple script to toggle (checked or not checked) all checkboxes on the page.


Copy this code and paste it in your HTML
  1. function toggleCheckboxes() {
  2. // written by Daniel P 3/21/07
  3. // toggle all checkboxes found on the page
  4. var inputlist = document.getElementsByTagName("input");
  5. for (i = 0; i < inputlist.length; i++) {
  6. if ( inputlist[i].getAttribute("type") == 'checkbox' ) { // look only at input elements that are checkboxes
  7. if (inputlist[i].checked) inputlist[i].checked = false
  8. else inputlist[i].checked = true;
  9. }
  10. }
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.