This javascript function can find all the checkboxes in given container and change the checked state.

Code Snippet

function CheckUncheckAll(container,isChecked) 
{
   var input = container.getElementsByTagName('input');
   var i = input.length;
 
   while (i--) 
   {
	if (input[i].type === 'checkbox') 
	{
		input[i].checked = isChecked;
	}
   }
} 

Sample Usage

<input type="button" name="CheckAll" value="Check All" 
onClick="CheckUncheckAll(document,true);">

<input type="button" name="UnCheckAll" value="Uncheck All" 
onClick="CheckUncheckAll(document,false);">

<input type="button" name="CheckAll" value="Check All" 
onClick="CheckUncheckAll(div1,true);">

<input type="button" name="UnCheckAll" value="Uncheck All"
onClick="CheckUncheckAll(div2,false);">


author's photo

Author : Blue Cloud

Just a normal software developer who love to write code. Developing professional software since 1999. After working in the software industry for many years, I've started my own website to share knowledges and experiences.

COMMENTS
blog comments powered by Disqus