DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

(un)Check All Checkboxes

01.07.2006
| 245 views |
  • submit to reddit
        
<html>
  <head>
    <script>
      function checkedAll (id, checked) {
	var el = document.getElementById(id);
	for (var i = 0; i < el.elements.length; i++) {
	  el.elements[i].checked = checked;
	}
      }
    </script>
  </head>
  <body>
    <form id="daform">
      <input type="checkbox" name="foo"/>
      <input type="checkbox" name="bar"/>
      <a href="javascript:checkedAll('daform', true)">all</a>
      <a href="javascript:checkedAll('daform', false)">none</a>
    </form>
  </body>
</html>