views:

32

answers:

2

How I can get select option text value in Java? Select options are in javascript.

<select id="colors" name="colorselector" >
   <option value="red"> Red </option>
   <option value="blue"> Blue </option>
   <option value="orange"> Orange </option>
   <option value="blue"> Yellow </option>
</select>
+3  A: 

Upon form submission, consider doing a request.getParameter("colorselector") in your servlet to retrieve the selected value.

limc
I want text node value ..as "Red" , "Blue" and not option value as "red" , "blue".
yogsma
@yogsma, you can only get the value defined using the option value attribute. If you want "Red", perhaps you need to store that in the option value attribute itself. Another way is to get the "red" value, then query against your database to retrieve the label ("Red").
limc
@limc - This is just sample example. What should I do if there are more than one options with same value , but different text node values.
yogsma
A: 

String stringname=request.getParameter("colorselector");

Rob Cooney