Reputation: 457
I have below code in one of my JSP.
<select name="item" id="item">
<option value="val1">One</option>
<option value="val2">Two</option>
<option value="val3">Three</option>
</select>
I know that I can get the value of <select>
by using request.getParamter("item"). At server side, I received val1/val2/val3 based on the option selected.
But at server side, I want to get One/Two/Three based on the option selected.
Upvotes: 0
Views: 363
Reputation: 1195
You can't access the text value in server side. If you still want both the value
and text
to be read in server side, alter the value
so that it contains both text
and value
<select name="item" id="item">
<option value="val1:One">One</option>
</select>
After you get the value, you can split the value to obtain both.
String selected[] = request.getParameter("item").split(":");
String selectedValue = selected[0];
String selectedText = selected[1];
Upvotes: 1