Saturday, February 23, 2008

Select or Deselect All Checkboxes, How to

<html>
<head>
<script>
function CheckAll()
{
count = document.frm.elements.length;
for (i=0; i < count; i++)
{
if(document.frm.elements[i].checked == 0)
{document.frm.elements[i].checked = 1; }
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 = 0;}
}
}
</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>

Simple as this, remember to change the form name, to your own form name. (Marked in Bold).

Got the code from here

If you like to learn more about SLIIT please visit www.sliit.lk

Subscribe To My Blog



AddThis Social Bookmark Button

No comments:

Post a Comment