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 Servlets and the fly likes checkbox problem 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 » Java » Servlets
Bookmark "checkbox problem" Watch "checkbox problem" New topic

checkbox problem

arpit singla
Ranch Hand

Joined: Jun 18, 2001
Posts: 66
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;

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...
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

you probably might get good help in the javascript
forum rather than the Servlet/JSP forum....sorry!
- satya

Take a Minute, Donate an Hour, Change a Life
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
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

Joined: Jun 18, 2001
Posts: 66
you can go to :
to get answer..
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
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++)
do whatever.....


So much trouble in the world -- Bob Marley
I agree. Here's the link:
subject: checkbox problem