File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "checkbox problem" Watch "checkbox problem" New topic
Author

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;

}
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

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
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
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
DC
you can go to : http://www.javaranch.com/ubb/Forum20/HTML/000574.html
to get answer..
thanks
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++)
{
if(YourCheckBoxName[i].checked)
do whatever.....
}

------------------
Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: checkbox problem