Top

Toggle All Checkboxes


Javascript Code
+ 0 likes
Please Register to submit score.
Bookmark and Share
Average Score  0.0 (of 0 scores)
Date Added  Oct 18, 2008
Last Updated  Nov 14, 2008
Tags  checkbox  checkboxes  form  input  onclick  toggle  toggleall 

Introduction

This is a 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:

Code:
<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'>


You can use this in multiple groups on the same page or form. Groups are determined by the checkbox id's which need to match followed by 1, 2, 3..

Grab the Code

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++;
	}
}
 

Comments

  (1)  RSS
napalm`
Comments: 182
 
Javascript Snippet:  Toggle All Checkboxes
Posted on Oct 19, 2008 11:31 pm
Looks handy.

Commenting Options

Register or Login to Hawkee.com or use your Facebook or Twitter account by clicking the corresponding button below.

  
Bottom