*/
Check out and contribute to CodePedia, the wiki for developers.

Other Views

corner
*/

How to Select or Deselect All Checkboxes

How to select or deselect all checkboxes?

The example shows how to allow the user to select rows of data by creating two buttons to select or unselect all checkboxes at once.

<html>
<head>
<script> 
function CheckAll()
{
count = document.frm.elements.length;
    for (i=0; i < count; i++) 
	{
    if(document.frm.elements[i].checked == 1)
    	{document.frm.elements[i].checked = 0; }
    else {document.frm.elements[i].checked = 1;}
	}
}
function UncheckAll(){
count = document.frm.elements.length;
    for (i=0; i < count; i++) 
	{
    if(document.frm.elements[i].checked == 1)
    	{document.frm.elements[i].checked = 0; }
    else {document.frm.elements[i].checked = 1;}
	}
}
</script>
</head>
<body>
<form name="frm">
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input type="checkbox" />
<input name="btn" type="button" onclick="CheckAll()" value="Check All"> 
<input name="btn" type="button" onclick="UncheckAll()" value="Uncheck All"> 
</form>
</body>
</html>


Related threads:
check all button

JavaScript FAQ
corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.