Solved

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

Posted on 2002-07-24
4
166 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 300 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here's how to start interacting with our community through Post.
Let’s face it: one of the reasons your organization chose a SaaS solution (whether Microsoft Dynamics 365, Netsuite or SAP) is that it is subscription-based. The upkeep is done. Or so you think.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 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