简体   繁体   English

比较并设置下拉列表中的选定值?

[英]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, 我正在从控制器中获取选定的值给我的asp,就像这样,

<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. 现在,我如何比较列表中的,如果${Questions}值为空,则应选择“选择问题”选项;或者,如果$ {Questions}值不为空,则应选择相应的值。

How can I implement the same. 我如何才能实现相同的效果。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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