• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting value and innerText of Select box in servlet

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Aji Ozkan
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why bother with innerText when the text attribute of the option contains the string you want?
hth,
bear
reply
    Bookmark Topic Watch Topic
  • New Topic