html:select supports it. if you have that select statement: <html:select property="startMonth"> <html:option value="0">Jan</html:option> ...
tomcat will automatically preselect the value for you depending on the value set for "startMonth" on the form. -james > -----Original Message----- > From: Fenderbosch, Eric [mailto:[EMAIL PROTECTED] > Sent: Thursday, November 06, 2003 1:21 PM > To: [EMAIL PROTECTED] > Subject: Specifying SELECTED for an <option> > > > I'm sure this question has been asked before, but I didn't > see any sort of archive here > http://jakarta.apache.org/taglibs/index.html#MailingLists. > > Is there an existing taglib or elegant way of specifying > "selected" for a <select><option>? Basically I want the HTML > to look like this: > > <select name="startMonth"> > <option value="0">Jan > <option value="1">Feb > <option value="2">Mar > <option value="3">Apr > <option value="4">May > <option value="5">Jun > <option value="6">Jul > <option value="7">Aug > <option value="8">Sep > <option value="9">Oct > <option value="10" selected>Nov > <option value="11">Dec > </select> > > Now I could do it something like this (where startMonth is in > my ActionForm): > > <select name="startMonth"> > <option value="0" <c:if test="${startMonth == > 0}">selected></c:if>>Jan > <option value="1" <c:if test="${startMonth == > 1}">selected></c:if>>Feb > <option value="2" <c:if test="${startMonth == > 2}">selected></c:if>>Mar > <option value="3" <c:if test="${startMonth == > 3}">selected></c:if>>Apr > <option value="4" <c:if test="${startMonth == > 4}">selected></c:if>>May > <option value="5" <c:if test="${startMonth == > 5}">selected></c:if>>Jun > <option value="6" <c:if test="${startMonth == > 6}">selected></c:if>>Jul > <option value="7" <c:if test="${startMonth == > 7}">selected></c:if>>Aug > <option value="8" <c:if test="${startMonth == > 8}">selected></c:if>>Sep > <option value="9" <c:if test="${startMonth == > 9}">selected></c:if>>Oct > <option value="10" <c:if test="${startMonth == > 10}">selected></c:if>>Nov > <option value="11" <c:if test="${startMonth == > 11}">selected></c:if>>Dec </select> > > But that seems inelegant. I'm surprised the <html:select> > tag doesn't have something like a selectedIndex or > selectedValue option. <html:select selectedIndex=startMonth> > <html:option/> > <html:option/> > <html:option/> > etc.... > </html:select> > > Am I missing a nice easy solution for this or is there > another tag lib which solves this? > > Thanks. > > Eric > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
