Forums Register Login

Getting value and innerText of Select box in servlet

+Pie Number of slices to send: Send
Hi
I have a jsp page.It contains select box
<select name="sbox">
<option value="101">text1</option>
<option value="101">text1</option>
</select>
Question is..
How do i get both value and text of a option element in Servlet
Which method of request object ll do the job?
In servlet if i say
request.getParameterValues("sbox").length
Its length is one ..
Can anyone help?
Ajit
+Pie Number of slices to send: Send
The client will return name=value as a key/value pair to your Servlet. The name of your select box is sbox, the value will be 101.
Since the both values are 101, the value returned to your servlet will always be 101.
How do i get both value and text of a option element in Servlet
The client only sends the name/value pair. It doesn't send the other text. Therefore the data won't be available to you unless you do something to get it yourself.
You might find that the text is already available in the Servlet from when the page was sent to the client. Otherwise you can set up some JavaScript on the client to send the select text as an extra parameter.
Dave
+Pie Number of slices to send: Send
Hi
I got the solution to get both value and innerText of select box
i take on hidden fied say with id="txt"
in script
function getForumName(selbox)
{

txt.value = selbox.all[selbox.selectedIndex].innerText.substring()
}

now this gives me selected options text
and request.getParameter("sbox") gives me value of option

cheers
+Pie Number of slices to send: Send
Why bother with innerText when the text attribute of the option contains the string you want?
hth,
bear
Catch Ernie! Catch the egg! And catch this tiny ad too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4254 times.
Similar Threads
[html form]Dropdown box lenght problem
Select tag 's selection should persist.
space delimited
Javascript Dynamic Dropdown Box validation
combo box selection in jsp
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:44:45.