在jsp页面显示下拉菜单的选定值 [英] display selected value of the drop down in jsp page
本文介绍了在jsp页面显示下拉菜单的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示选定的值。在文本字段中,我可以在下面的值中显示它。
value =<%= event_data.getE_venue()%> ;
code:
< input type =textname =whereplaceholder =Add a placesize =23value =<%= event_data.getE_venue()%>/>
< option>运动< / option>
< option> Corporate< / option>
< option>宗教< / option>
< option>音乐< / option>
< / select>
但在下拉框中不起作用。
请帮助我。谢谢..
解决方案
首先,选择不会以这种方式工作,您需要将选定的属性放在与您的输入。
例如:
< option selected ='selected'> Sports< / option>
检查这个小提琴:
你的代码应该是这样的:
< input type =textname =whereplaceholder =添加地点size =23value =<% = event_data.getE_venue()%>中/>
< select name =categoryid =single1>
< option<%=(event_data.getE_target_category()。equals(Sports)?selected ='selected':)%>> Sports< / option>
< option<%=(event_data.getE_target_category()。equals(Corporate)?selected ='selected':)%>> Corporate< / option>
< option<%=(event_data.getE_target_category()。equals(Religious)?selected ='selected',)%>>宗教< / option>
< option<%=(event_data.getE_target_category()。equals(Music)?selected ='selected':)%>> Music< / option>
< / select>
I want to display selected value. In the text field I can display it within value like below
value ="<%=event_data.getE_venue()%>"
code :
<input type="text" name="where" placeholder="Add a place" size="23" value ="<%=event_data.getE_venue()%>"/>
<select name="category" value ="<%=event_data.getE_target_category()%>" id="single1">
<option>Sports</option>
<option>Corporate</option>
<option>Religious</option>
<option>Music</option>
</select>
but in dropdown box it doesn't work. please help me. thanks..
解决方案
Firstly, select doesn't work in that way , you need to put selected attribute in option that matches your input.
for example:
<option selected='selected'>Sports</option>
check this fiddle :
your code should be something like :
<input type="text" name="where" placeholder="Add a place" size="23" value ="<%=event_data.getE_venue()%>"/>
<select name="category" id="single1">
<option <%= (event_data.getE_target_category().equals("Sports")?"selected='selected'":"") %>>Sports</option>
<option <%= (event_data.getE_target_category().equals("Corporate")?"selected='selected'":"") %>>Corporate</option>
<option <%= (event_data.getE_target_category().equals("Religious")?"selected='selected'","") %>>Religious</option>
<option <%= (event_data.getE_target_category().equals("Music")?"selected='selected'":"") %>>Music</option>
</select>
这篇关于在jsp页面显示下拉菜单的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文