Link to home
Create AccountLog in
Avatar of pavelmed
pavelmed

asked on

When using Select in a form, how do i send the multiple selections to a servlet?

Hi, I'm trying to figure out how to write a servlet that has a Select in which users can select multiple entries, and a
submit button that sends the values of the selected attributes to a servlet.  Here's a simple example i tried to make,
but it doesn't work (the servlet recieves only the first of the selected items).  Please help

;test.servlet
(servlet (age)
    (case age ((#null)
        {<html><head><title>Test Form</title></head>  
         <body>  
           <form method="get" action="test.servlet">  
             Select sereval of these numbers:
             <select name=age size=5 multiple>  
               <option value=10> 10 </option>
               <option value=20> 20 </option>
               <option value=30> 30 </option>
               <option value=40> 40 </option>
               <option value=50> 50 </option>
             <input type="submit">  
             </select>
           </form>  
         </body></html>})
     (else
       {<html><head><title>Test Form</title></head>  
        <body>  
           You selected
           [age]
        </body></html>})))

Avatar of bubbledragon
bubbledragon

use String array?

String[] arrValues[] = request.getParameterValues("age");
Avatar of jessegivy
Hi bubbledragon,

The second set of brackets aren't required right?  Happens to the best of us, should look like this:

String[] arrValues = request.getParameterValues("age");
Avatar of pavelmed

ASKER

I'm not really sure what you meab by :
String[] arrValues = request.getParameterValues("age");
That looks like Java.
I am using JScheme for my servlet.  (http://www-swiss.ai.mit.edu/~jaffer/r4rs_toc.html)
Could you please show how and where to insert that in my code (because just putting it
in before [age] on the second to last line doesn't work).

Thanks a lot


-------------
Also, in the above code i accidentally put the  <input type="submit">   inside the select.  
So here's the corrected code:

;test.servlet
(servlet (age)
    (case age ((#null)
        {<html><head><title>Test Form</title></head>  
         <body>  
           <form method="get" action="test.servlet">  
             Select sereval of these numbers:
             <select name=age size=5 multiple>  
               <option value=10> 10 </option>
               <option value=20> 20 </option>
               <option value=30> 30 </option>
               <option value=40> 40 </option>
               <option value=50> 50 </option>
             <input type="submit">  
             </select>
           </form>  
         </body></html>})
     (else
       {<html><head><title>Test Form</title></head>  
        <body>  
           You selected
           [age]
        </body></html>})))
ASKER CERTIFIED SOLUTION
Avatar of jessegivy
jessegivy
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
...sorry, and as to where, it's at the top of the page, or really, it doesn't exactly matter where it is.  I'm NOT familiar with JScheme, I'll check it out.