Select/Deselect all checkbox with 1 click?
Posted: Sun Dec 10, 2006 10:49 am
how can I do this. I have hundreds of check box that needs to be checked or unchecked and checking them all manually would be a pain.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<form name="frmchk">
........................................................................
<input type="checkbox" name="chk" value="1">
<input type="checkbox" name="chk" value="1">
........................................................................
<input type="button" value="Check All" onClick="chk_all()">
</form>Code: Select all
var hld = document.getElementsByName("chk");
function chk_all()
{
for (i=0;i<=hld.length-1;i++)
{
hld[i].setAttribute("checked", "1");
}
}Code: Select all
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title> Created On php Designer 2007 </title>
<script>
var hld = document.getElementsByName("chk");
function chk_all()
{
for (i=0;i<=hld.length-1;i++)
{
hld[i].setAttribute("checked", "1");
}
}
</script>
</head>
<body>
<form name="frmchk">
........................................................................
<input type="checkbox" name="chk" value="1">
<input type="checkbox" name="chk" value="1">
<input type="checkbox" name="chk" value="1">
<input type="checkbox" name="chk" value="1">
........................................................................
<input type="button" value="Check All" onClick="chk_all()">
</form>
</body>
</html>