Select/Deselect all checkbox with 1 click?
Moderator: General Moderators
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
Select/Deselect all checkbox with 1 click?
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.
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
Give Every Check Box The Same Name And se A Button To Check All
===============================================
And So A Sample HTML Page Would Be Like This
====================================
===============================================
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>