We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

davaodude on 03/29/07


Tagged

form checkbox


Versions (?)


Who likes this?

3 people have marked this snippet as a favorite

luman
vali29
f0vela


Toggle all form checkboxes


Published in: JavaScript 


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

  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 

You need to login to post a comment.