Thanks for all the help.

My situation is slightly different.  Following is part of the html code:

  <td><input type="checkbox" name="OtherInterest" value="Traveling">
Traveling</td>
  <td><input type="checkbox" name="OtherInterest" value="Fishing">
Fishing</td>

Name "OtherInterest" is not known to the servlet.  I can't hard coded it
in the servlet.  That's why it causes problems when user doesn't check
either Fishing or Traveling because the parameter name "OtherInterest"
will not be return by getParameterNames() at all.

The reason I need to put "Traveling" and "Fishing" as the values rather
then "true" is because I need the actual string.  So if user click on
"Traveling", the string "Traveling" will be return.  If both were
checked, the return string will be "Traveling,Fishing" by calling
req.getParameter();  I need the actual strings "Traveling" and "Fishing"
to update the database.

Again, thanks for all your advice.

- Thomas -


John Larson wrote:
>
> Thomas,
>
> The checkbox behavior is surprising, but normal.....
>
> You can use the following code to retrieve the values:
>
> String[] frmCourseKey = req.getParameterValues("check_box");  //This is
> the parm name
>
>  for (int i = 0;i < frmCourseKey.length; i++)
>   {
>      String courseKey = frmCourseKey[i]
>      Do the rest of your processing with the value......
>   }
>
> Good luck,
> John
>
> Thomas To wrote:
> >
> > Hi all,
> >
> > I'm writing a servlet to get input values from an HTML form and put them
> > into the database.  I use both input type="text" and input
> > type="checkbox".  In the servlet makes call to
> > ServletRequest.getParameterNames() and ServletRequest.getParameter() to
> > retrieve all the parameters and their values.  I realize that for all
> > text type, if nothing is put in, the parameter name will be return and
> > the value is an empty string.  However, for checkbox type, if all
> > checkboxes are unchecked, getParameterNames() will not even return the
> > parameter name.  Is this normal?  Is there any way that
> > getParameterNames() will return the parameter name with empty string
> > like the text type?
> >
> > Can anyone give me some info on this?
> >
> > Thanks.
> >
> > - Thomas -
> >
> > ___________________________________________________________________________
> > 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
>
> ___________________________________________________________________________
> 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

___________________________________________________________________________
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