Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

<select ... <option... handling on the server side

Posted on 2002-07-24
4
Medium Priority
?
169 Views
Last Modified: 2011-10-03
Hi!

I have a couple of dynamically created <select size="10" multiple> elements (http://www.w3.org/TR/REC-html32#select). I'm wondering if it is possible to retrieve several <option> values from one <select> on to the server side?

I tried to list the parameters received by the servlet with the following snippet:

    Enumeration e   = request.getParameterNames();
    String s        = "";
    while ( e.hasMoreElements() ) {
      s = (String)e.nextElement();
      System.out.println( "Param: <" + s + "> Value: <" + (String)request.getParameter(s) + ">" );
    }


But I received only one value from each <select> (both had multiple options selected):

Param: <listboxFooBar> Value: <foo>
Param: <listboxBarFoo> Value: <bar>
Param: <Submit> Value: <Tallenna>

I will increase the points for this question to 300 if a solution is found. If no solution is found then the first one to answer "it can't be done" will get the points :D


Regards,

Marko
0
Comment
Question by:_marko_
  • 3
4 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 7175270
it can't be done.

(actually, I think it can ... but just in case it can't, I wanted to be first:)

stand by, I'll look into it ...
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 1200 total points
ID: 7175339
use request.getParameterValues instead ... which returns a String[] ... for example:



<HTML>
<BODY>
<FORM name='myform' method='post'>
 <SELECT name='myselect' multiple>
  <OPTION value='0'>Zero</option>
  <OPTION value='1'>One</option>
  <OPTION value='2'>Two</option>
  <OPTION value='3'>Three</option>
  <OPTION value='4'>Four</option>
  <OPTION value='5'>Five</option>
  <OPTION value='6'>Six</option>
  <OPTION value='7'>Seven</option>
 </select>
 <INPUT type='submit'>
</form>
<P>
<%
  String[] sa = request.getParameterValues("myselect");

  for ( int i=0; i<sa.length; i++ )
  {
    %><%= sa[i] + ", " %><%
  }
%>
</body>
</html>
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 7175351
forgot to check for nulls ...


  if ( sa==null )
  {
     %><%=request.getParameter("myselect")%><%
  }
  else for ( int i=0; i<sa.length; i++ )
  {
     %><%= sa[i] + ", " %><%
  }
0
 
LVL 2

Author Comment

by:_marko_
ID: 7176475
Hello knightEknight!

Yes :-) That was exactly what I was looking for. Sorry for the delay (was out of the office).


Thanks!


Marko
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question