Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Select value

 
vasuma patel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I get the selected value of a dropdown box( HTML select) from request object?

Thanks in advance

Vasuma
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With getParameter() just like any other form element.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that you'll get the value of the selected option, not the text displayed in the combobox.
 
vasuma patel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok.. Thanks. I was using getParameter() but am getting null and so thought there is something different to do with select. I will check what I was doing wrong.
 
Uma Mahi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<option value="test">test</option>

set the value attribute for the option tag
 
sushma sree
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code should look something like this:

<select name="selectedItem">
<option value="1">Value1</option>
<option value="2">Value2</option>
</select>

And in your code, you can retrieve it using

request.getParamter("selectedItem");

Incase you have a list box rather than a select box like

<select name="selectedItems" multiple>
<option value="1">Value1</option>
<option value="2">Value2</option>
</select>

your code should then be

request.getParameterValues("selectedItems");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic