File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Check All / UnCheck All Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Check All / UnCheck All" Watch "Check All / UnCheck All" New topic
Author

Check All / UnCheck All

Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

I've got a series of checkboxes on a form. I'd like to have 2 "convenience links" where folks can click the "Check All" or "Uncheck All" in order to do just that... kind of like they have on a mail box, like Yahoo.
I did a search in this forum, and couldn't seem to find something like this. Any ideas?
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
Generally speaking, you have to loop through and check/unchek them
The trick there is to get your checkboxes pointers.
1. if all checkboxes to be checked have the same name, you can do
function setChecked(isChecked){
var arr = document.getElementsByName("checkboxesName");
for(var i=0;i<arr.length;i++){
arr[i].checked=isChecked;
}
}
2. Otherwise you can do:
function setChecked(isChecked){
var arr = document.form.elements;
for(var i=0;i<arr.length;i++){
if(isValid(arr[i]))arr[i].checked=isChecked;
}
}

function isValid(element){
return element.type="checkbox";
}
Function isValid could be more complicated, like checking that name starts with some preffix, or check className or id or value - it is all up to you.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Jess here is what I talked about to you using the option 1 adusted to your needs plus another feature you may like.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Check All / UnCheck All
 
Similar Threads
select and unselecting checkboxes based on clicking a check box
JARS are visible threrough RAD 7.0
Check/Uncheck check boxes when All check box is enabled/disabled...
Setting checkboxes on/off from Javascript
check box