简体   繁体   中英

Compare and set the selected value in drop down list?

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.

尝试检查所选索引是否为0,然后显示“选择问题” [假设下拉列表的第一项是“选择问题”],否则您可以根据获取的索引将所选选项的选定属性设置为true。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM