Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checkbox problem

 
arpit singla
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have following function in javascript to go through an array of checkboxes to determine if any of the checkbox was checked:
var test = document.myform.elements.length;
for(var i=0; i < test; i++)
{
if((document.myform.elements[i].type == "checkbox")&& (document.myform.elements[i].name.checked))
{
alert('inside if block');
return true;

}
else
return false;

}
document.myform.elements[i].name returns the right name of checkbox but document.myform.elements[i].name.checked returns undefined.
could anyone help...
thanks
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

you probably might get good help in the javascript
forum rather than the Servlet/JSP forum....sorry!
- satya
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont have a book handy but there is something wrong with this line:
if((document.myform.elements[i].type == "checkbox")&& (document.myform.elements[i].name.checked))
Im not 1000% sure but the .name.checked just doesnt look right. If I can find a book around here Ill write back & let you know.
 
arpit singla
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DC
you can go to : http://www.javaranch.com/ubb/Forum20/HTML/000574.html
to get answer..
thanks
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After determining that the form element is a checkbox. You still need a loop to determine which of the checkboxes is selected (This is assuming there are several possible values for one checkbox name)
for (var i = 0; i < yourCheckBoxName.length; i++)
{
if(YourCheckBoxName[i].checked)
do whatever.....
}

------------------
Bosun
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic