File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 63838

Moved to HTML/Javascript.

[Asking smart questions] [About Bear] [Books by Bear]
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
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
It's not a secret anymore!