Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How can I select all check boxes with one click

Posted on 2011-09-15
4
Medium Priority
?
346 Views
Last Modified: 2012-05-12
Hi..
I have series of checkboxes.
If I click on select all it should automatically select all checkboxes in the page.

I can give better example for this .i.e GMail. When you click select all ,,it should automatically selected all the check boxe(all mails)..

same way I want to do that in classic asp. Is any one have idea about this
0
Comment
Question by:lucky20
  • 2
4 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 1000 total points
ID: 36544043
0
 
LVL 1

Author Comment

by:lucky20
ID: 36544274
@leakim971

I forget to mention I am displaying checkboxes(in directly it is using the id value of item ..and i am getting these values form sql).

I tried to use the code mentioned above examples.

It didn't work for me.

Initially...
<tr><th>ID</th>
<th>Name</th></tr>
<tr><td>
<input type="checkbox" name="chk" value="<%= rs("id") %>"></td>
<td><%= rs("Name")%></td></tr>



After

<tr><th>ID<input type="checkbox" name="selectall" onclick="selectall()"></th>
<th>Name</th></tr>
<tr><td>
<input type="checkbox" name="chk" value="<%= rs("id") %>"></td>
<td><%= rs("Name")%></td></tr>


the select all function is not working

[code]function selectall () {  
  var elems = chk.form1.elements;  
  var checked = chk.checked;  
  var id = chk.id;  
  for (var i=0, n=elems.length;i<n;i++) {  
    if (elems[i].id && elems[i].id.indexOf(id)==0) {  
      elems[i].checked = checked;  
    }   
  }  
}  

Open in new window

0
 
LVL 34

Expert Comment

by:Big Monty
ID: 36544483
try this as your selectall function:

function selectall() {
   var elems = document.form[0].elements;
   var elemsName = new String;

   for( var index = 0; index < elems.length; index++ ) {
        elemsName = elems[index].name;
        if( elemsName.indexOf( 'chk' ) > 0 )
             elems[ index ].checked = true;
   }

}
0
 
LVL 34

Assisted Solution

by:Big Monty
Big Monty earned 1000 total points
ID: 36544493
and if you want to make it a select/unselect all function, you can change it to:

function selectall() {
   var elems = document.form[0].elements;
   var elemsName = new String;

   for( var index = 0; index < elems.length; index++ ) {
        elemsName = elems[index].name;
        if( elemsName.indexOf( 'chk' ) > 0 )
             elems[ index ].checked = ( ! elems[ index ].checked );
   }

}
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question