File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Catching the content of drop down box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Catching the content of drop down box" Watch "Catching the content of drop down box" New topic

Catching the content of drop down box

Prasad Darsi

Joined: Sep 26, 2004
Posts: 16
I declared the drop-down menu as shown below:

<form name="myForm" action="form2.jsp">
<select name="Fruits">
<option value="" selected>Select A Fruit</option>
<option value="1">Orange</option>
<option value="2">Apple</option>
<option value="3">Banana</option>
<input type="submit" value="Submit">

After submitting the form, I am catching the value of "Fruits", and it is showing either 1,2, or 3.

I want to catch both the value and its content in "form2.jsp" so that I can post that data in the database. When the form is submitted, The value of "Fruits" is showing one of 1,2 or 3.

Is there anyway by which I can catch both the content of the drop-down box ?

Thanks in advance,
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
This is a jsp question, moving there.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63026

The display text of the drop-down box is not submitted.

Presumably, you already have this info on the server so that you could generate the select element in the first place. Use the submitted value to look up the corresponding text.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Prasad Darsi

Joined: Sep 26, 2004
Posts: 16
I can fetch this value from the server by using one more query. But to do this, I have to access the database again.

Can we avoid this database access, so that I can get these two values quickly ? (I can also save some lines of code)
Consider Paul's rocket mass heater.
subject: Catching the content of drop down box
It's not a secret anymore!