drop down

Hello All,

I have a requirement such that if the user enters a number in the text box ...the drop sown has to show that number as a default selected...I know that there is an attribute called selected but not able to make correct use if it ...any example is greatly appreciated...

Thanks,

Greeshma...

[325 byte] By [Greeshma12a] at [2007-11-27 4:56:07]
# 1
That's just basic HTML knowledge. Check the HTML spec at w3.org: http://www.w3.org/TR/html4/interact/forms.html#h-17.6.1<option value="value1" selected>label1</option>
BalusCa at 2007-7-12 10:11:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks for your reply ...as I said I know about the selected attribute but I need the way to make the drop down element selected depending on the text box...Thanks,Greeshma
Greeshma12a at 2007-7-12 10:11:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Then I don't understand the specific coding question. All you need to do is to add the 'selected' attribute to the <option> element when needed.
BalusCa at 2007-7-12 10:11:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Let me give an example :consider a drop down with all the dates...how to select today's date because a similar situation exists in my application depending on the number entered in the text box (after he hits enter ) the drop drop should select that value by default...

Thanks,

Greeshma

Greeshma12a at 2007-7-12 10:11:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
You can add a javascript event to your text box e.g.onchange="form[0].options[form[0].box..value].selected=true;"
Niklasa at 2007-7-12 10:11:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Thanks that helps...
Greeshma12a at 2007-7-12 10:11:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Thanks for your reply ...but what if there is no text box...ie., if the user selects an option goes back to the previous page hitting the back button and comes to same page again, then how can we make the dropdown populate with the seleceted value...

Help is greatly appreciated...

Thanks,

Greeshma...

Greeshma12a at 2007-7-12 10:11:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Thanks Got it :)

Did something like this ;

<option ><c:choose>

<c:when test="cond">

<c:out value="selected"/>

</c:when>

<c:otherwise>

<c:out value=""/>

</c:otherwise>

</c:choose>>

<c:out value="${value}"/>

</option>

Thanks...

Greeshma12a at 2007-7-12 10:11:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...