Solved

How can I select all check boxes with one click

Posted on 2011-09-15
4
337 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 82

Accepted Solution

by:
leakim971 earned 250 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 33

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 33

Assisted Solution

by:Big Monty
Big Monty earned 250 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CSS Question.. 3 87
classic asp checkbox uncheck and check 2 62
ASP server side get value 15 24
Syntax for query to update table 2 14
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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