?
Solved

How can I select all check boxes with one click

Posted on 2011-09-15
4
Medium Priority
?
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 82

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

777 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