ServletRequest and combo box newbie question

S

Santosh

Hi,
Here is a brief description of what my prblem is:
I have a Combo box in a jsp page that is populated from the database.
The following code snippet shows how i am populating the combo box.

//data from the database is there in an Enumeration object tempEnum
Integer tempInt;
int tempctr=0;
while(tempEnum.hasMoreElements()){
tempInt=((Integer)tempEnum.nextElement());
tempctr++;
%>
<option value="<%=tempctr%>"><%=tempInt.toString()%></option>
<%
}
%>
I am using a counter (tempctr) to set the values of the combo box
option as I will need that for further calculations.

My Question:
I, not only need to know the option value that is selected, I also
need to know the option that is selected.

say for example if the output of the combo box after being populated
is:
<select name="select">
<option value="1">3</option>
<option value="2">6</option>
<option value="3">8</option>
<option value="4">9</option>
<option value="5">10</option>
</select>

In the above case, if the user selects the 3rd option:
<option value="3">8</option>
I want to read the value (3 in this case) and also the option (8). How
can I do that using ServletRequest object? Right now I am able to read
the value by calling:
request.getParameter("select");

I am newbie to java so please excuse my ignorance.
-Santosh
 
A

Andrew Thompson

On 8 Sep 2004 10:32:47 -0700, Santosh wrote:

Probably a very bad answer, but it occurred
to me that since you are *putting* the data
into the select..
<option value="<%=tempctr%>"><%=tempInt.toString()%></option>

...you might do (something like) this..

<option
value="<%=tempctr%>-<%=tempInt.toString()%>">
<%=tempInt.toString()%>
</option>

That way you can get both the counter
*and* the value displayed in the option.

HTH
 
C

Chris Smith

Santosh said:
<select name="select">
<option value="1">3</option>
<option value="2">6</option>
<option value="3">8</option>
<option value="4">9</option>
<option value="5">10</option>
</select>

In the above case, if the user selects the 3rd option:
<option value="3">8</option>
I want to read the value (3 in this case) and also the option (8). How
can I do that using ServletRequest object? Right now I am able to read
the value by calling:
request.getParameter("select");

This isn't a Java issue; it's an HTML/HTTP issue, and no choice of
programming language would be able to solve your problem. The text
displayed in a drop-down box form element is not sent by the browser to
the server; so you will need to include all the information in the value
parameter. There is simply no other way to do it.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top