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

  • submit to reddit
      function checkedAll (id, checked) {
	var el = document.getElementById(id);
	for (var i = 0; i < el.elements.length; i++) {
	  el.elements[i].checked = checked;
    <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>