Hi,

If I'm not wrong your problem is:
 - you don't know in advance what fields might be interesting...
 - also don't know in advance if a single option within
  a checkbox is NOT checked (cos browsers sends only checked fields.

If so, HTML writers should add two hidden fields within their forms:
 - one with the name of the ineresting checkbox ("OtherInterest"
   in this case.
 - another with all possible checkbox values.

So add to your form:
 <input type=hidden name=TosCheckbox value="OtherInterest">
 <input type=hidden name=TosValues
        value="Traveling,Fishing,Swiming,Jumping"
 >
...(add here the checkbox fields for Traveling, Fishing, Swiming, Jumping).

And within your servlet get first these known parameters to find out:
 - how the checkbox you want to parse is named.
 - wich are its possible values - set them in advance to "not checked"
   and only for parameters actually received set them to "checked"

Generally speaking,
if you expect parameters and  dont know their names in advance, nor their
possible values,
you need some other means (like hidden fields within the same posted form)
to figure out wich are these.

Cezar

On Fri, 16 Apr 1999, Hans Bergsten wrote:

> Thomas To wrote:
> >
> > 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.
>
> I'm not sure if this will help you, but it might.
>
> You can add a hidden field with the same name as the checkbox fields and
> an empty string as its value. This way you will always get a parameter
> with this name, even if none of the checkboxes is checked.
>
> In you servlets you could do something like this:
>
>   Hashtable parsedParams = new Hashtable();
>   String[] names = req.getParameterNames();
>   for (int i = 0; i < names.length; i++) {
>     String param = names[i];
>     String[] values = req.getParameterValues(param);
>     Vector parsedValues = new Vector();
>     for (int j = 0; j < values.length; j++) {
>       String value = values[i];
>       // Get rid of empty strings
>       if (value.length() != 0) {
>         parsedValues.addElement(value);
>       }
>     }
>     parsedParams.put(param, parsedValues);
>   }
>
>   Enumeration validParams = parsedParams.keys();
>   while (validParams.hasMoreElements) {
>     Vector validValues = (Vector) validParams.nextElement();
>     if (validValues.size() == 0) {
>       // Process empty text field or empty checkbox value
>     }
>     if (validValues.size() == 1) {
>       // Process filled out text field or single-value checkbox value
>     }
>     if (validValues.size() > 1) {
>       // Process multi-value checkbox value
>     }
>   }
>
> If you need a way to distinguish between empty/single-value text fields
> and empty/single-valued checkboxes you can use some naming convention
> for the field names.
>
> I hope this helps you solve the problem.
>
> --
> Hans Bergsten           [EMAIL PROTECTED]
> Gefion Software         http://www.gefionsoftware.com
>
> ___________________________________________________________________________
> 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
>


Cezar Totth                             email:  [EMAIL PROTECTED]
                                        Fax:    (401) 220 33 95
Genesys Software Romania                Phone:  (401) 638 49 44
Stefan Furtuna 169, sect.6
cod 77171, Bucharest
Romania

___________________________________________________________________________
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