display selected value of the drop down in jsp page

html, java, javascript, jsp

Solution

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 :

http://jsfiddle.net/ZLTS7/

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>

Problem

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..

Original source