Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Check/Uncheck All Multibox

 
kobe phenom
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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++){
if(chkAll.checked){
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you send the whole html code?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to HTML/Javascript.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Been answered many times before: http://www.coderanch.com/t/116148/HTML-JavaScript/Select-All

Eric
 
kobe phenom
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic