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)
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'> |