Compare and set the selected value in drop down list?

652 views Asked by At

I have used the dynamic drop down list. Now In that list I need to set the selected value.

I am getting the selected value to my asp from my controller, it is some thing like this,

<c:set var="Questions" value='${map["Questions"]}' />

Below shared is the source code for my drop down list.

<tr>
<c:set var="questionids" value="Select Question,Visit Dentist?,Age (40+),Drinker?,Smoker?" scope="application"/>
<select name="questionid" id="questionids" >
       <c:forEach items="${fn:split(questionids, ',')}" var="questionids">
         <option value="${questionids}">${questionids}</option>
       </c:forEach>
</select>
</tr>

Now how do I compare the in the list, that if the ${Questions} value is null then "Select Question" option should be selected OR if the ${Questions} value is not null then the respective value should get selected.

How can I implement the same.

1

There are 1 answers

0
Djk On BEST ANSWER

Try checking selected index if it is 0 then show "Select Question"[Assuming 1st entry to dropdown list is "Select Question"] otherwise you can set selected attribute to true of corresponding option based on index you're getting.