Solved

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

Posted on 2002-07-24
4
159 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
Comment Utility
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
Comment Utility
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
Comment Utility
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_
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now