aspose file tools*
The moose likes Servlets and the fly likes Getting value and innerText  of Select box in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting value and innerText  of Select box in servlet" Watch "Getting value and innerText  of Select box in servlet" New topic
Author

Getting value and innerText of Select box in servlet

Ajit Kanada
Ranch Hand

Joined: Jan 23, 2001
Posts: 95
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
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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
Ajit Kanada
Ranch Hand

Joined: Jan 23, 2001
Posts: 95
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Why bother with innerText when the text attribute of the option contains the string you want?
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting value and innerText of Select box in servlet