Select/Deselect all checkbox with 1 click?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Select/Deselect all checkbox with 1 click?

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There have been multiple threads on "check all" type features, plus Google is full of resources too.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post 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>
Post Reply