Current value from drop-down list?

I have a form that allows a user to update their details.

The form displays the current details. One of my input fields is a drop down list. How can I get the drop down list to display the current value for this field (i.e. the value the user entered the first time the submitted their details) ?

[332 byte] By [fagane] at [2007-9-26 2:05:51]
# 1
<select name="select"> <option value="1">1</option> <option value="2" selected>2</option> <option value="3">3</option></select>
TomTong at 2007-6-29 8:51:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

> field (i.e. the value the user entered the first time

> the submitted their details) ?

IMO, the user will only SELECT a value, not ENTER.

When the form is submitted, the selected value should

be available as a parameter on the request object as a

name-value pair. In the above example, the name of the

parameter will be "select" and the value would be either

"1" or "2" or "3".

HTH.

- madhav

mlakkapr at 2007-6-29 8:51:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Suppose at the time of submitting information the user selected his/her gender from the drop down menu.

<select size="1" name="menu">

<option selected value="male">male</option>

<option value="female">female</option>

</select>

Now if the user has selected option "female" at the time of registration and you want to display the same again at the time of modifying the information then do the following.

At the time of registration you must have saved all the values in a database so first retrieve it. Suppose there is a column named "gender" in a table where you are saving value.

rs.getString("gender");

Now you will have to compare this value for every option in the drop down menu like this:

<select size="1" name="menu">

<option ><%if rs.getString("gender")="male" {%> value=male selected>male</option><% } %>

<option ><%if rs.getString("gender")="female" { %>value=female selected>female</option> <% } %>

</select>

bye

TechMan5 at 2007-6-29 8:51:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...