Solved

How can I select all check boxes with one click

Posted on 2011-09-15
4
335 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 32

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 32

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now