Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How can I select all check boxes with one click

Posted on 2011-09-15
4
Medium Priority
?
344 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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