Category: >> JavaScript >> Toggle All Checkboxes on or off Bookmark and Share

<< lastnext >>

Snippet Name: Toggle All Checkboxes on or off

Description: Simple Javascript snippet that lets you toggle a group of checkboxes on or off at the same time. This is the format for your HTML form.

Comment: (none)

Author: CoderZone
Highlight Mode: JAVASCRIPT
Last Modified: March 01st, 2009

function toggleAll(id){
     box = document.getElementById(id);
     if(box.checked == true)
          var setting = true;
          var setting = false;
     var cur_id = id+'1';
     var count = 1;
     while(box = document.getElementById(cur_id))
          box.checked = setting;
          cur_id = id+count;
<input type=checkbox id='toggleall' onClick="toggleAll('myform');"> Toggle All
<input type=checkbox id='myform1'>
<input type=checkbox id='myform2'>
<input type=checkbox id='myform3'>
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© | users online: 7