?
Solved

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

Posted on 2002-07-24
4
Medium Priority
?
167 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Check out the latest tech news, community articles, and expert highlights in August's newsletter.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

801 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