This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes HTML, CSS and JavaScript and the fly likes Check/Uncheck All Multibox  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Check/Uncheck All Multibox  " Watch "Check/Uncheck All Multibox  " New topic

Check/Uncheck All Multibox

kobe phenom

Joined: Aug 24, 2003
Posts: 11
I was able to check and uncheck a set of checkboxes I just edited a line in the sample code given to me.

function checkAll(){
var chkBoxes = document.forms[0].myArray
var chkAll = document.getElementById("chkAll");

for(i=0; i<chkBoxes.length; i++){
chkBoxes[i].checked = true;
} else {
chkBoxes[i].checked = false;
It works fine for cases where my multibox has more than one item but it does not work for cases where the multibox has only one item. The length of chkBoxes is undefined in this case. Could you help me how to fix it? Thanks in advance
Kartik Patel
Ranch Hand

Joined: Sep 12, 2005
Posts: 73
can you send the whole html code?

Chop your own wood, and it will warm you twice. - Henry Ford
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 61082

Moved to HTML/Javascript.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15376
Been answered many times before:

kobe phenom

Joined: Aug 24, 2003
Posts: 11
Many Thanks
I agree. Here's the link:
subject: Check/Uncheck All Multibox