CoderZone.org

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
Language: JAVASCRIPT
Highlight Mode: JAVASCRIPT
Last Modified: March 01st, 2009

function toggleAll(id){
     box = document.getElementById(id);
 
     if(box.checked == true)
     {
          var setting = true;
     }
     else
     {
          var setting = false;
     }
 
     var cur_id = id+'1';
 
     var count = 1;
     while(box = document.getElementById(cur_id))
     {
          box.checked = setting;
          cur_id = id+count;
          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 
© coderzone.org | users online: 7