Page 1 of 1

Select/Deselect all checkbox with 1 click?

Posted: Sun Dec 10, 2006 10:49 am
by psychotomus
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.

Posted: Sun Dec 10, 2006 10:51 am
by feyd
There have been multiple threads on "check all" type features, plus Google is full of resources too.

Posted: Mon Dec 11, 2006 12:08 am
by neel_basu
Give Every Check Box The Same Name And se A Button To Check All
===============================================

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");
      }
  }
And So A Sample HTML Page Would Be Like This
====================================

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>