Checkbox values get returned only if they are checked.  In this case,
both checkboxes return the value "ON" which isn't what you want.
Try:
   <input type=checkbox name="Male">
   <input type=checkbox name="Female">

(Notice that I haven't assigned values to the checkboxes since we only
care if it's checked or not.)

Then something like this will tell you if the checkboxes have been
checked:
   boolean maleChecked = (req.getParameter("Male") != null);
   boolean femaleChecked = (req.getParameter("Female") != null);

But like Bob Withers said, this is a case where you probably want to use
radio buttons rather than checkboxes, in which case follow his radio
button example.


Russell Montgomery
Digital Renaissance

> -----Original Message-----
> From: SUH [SMTP:[EMAIL PROTECTED]]
> Sent: Saturday, March 13, 1999 2:17 AM
> To:   [EMAIL PROTECTED]
> Subject:      how do you know which chechbox was checked ?
>
>
> Hi,
>
> I'm writting Web pages contianing some checkboxes.
>
> But I can't verify which checkbox was selected:
>
> For example>>
> <input type="checkbox" name="male" value="ON">
> <input type="checkbox name="female" value="ON">
>
> Then
>
> A user will check one of checkboxes.
>
> In servlet
> ,
>
> req.getParameter("male");
> OR
> req.getParameter("female");
> These are not working. The statements always return "ON".
> I want to know which one was checked.
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to