JSP下拉列表的选定值

时间:2014-08-29 05:09:48

标签: java jsp

在我的JSP页面中,我使用弹出窗口将新的沉淀剂添加到下拉列表中。它工作正常,但问题是如果我添加一个,dorpdown显示"添加新"而不是" - 请选择 - "

这是我后来尝试的

<c:if test="${listop.precipitants eq listop.precipant}">Selected </c:if>

并获得Unterminated <form:option tag例外

这是我的控制器代码

    map.put("precipitantdroplist", bioprofileservice.listPrecipitantdrop());
    map.put("Precipitantdropfam", new Precipitantsdrop());

和JSP

<form:select  path="precipant" id="precipant" onchange="showpopup(this.options[this.selectedIndex].value,this.form,'Newprecipant?#login_form3');">
 <form:option value="">--Please Select--</form:option>
 <c:if test="${!empty precipitantdroplist}">
                <c:forEach items="${precipitantdroplist}" var="listop">
                <form:option value="${listop.precipitants}" <c:if test="${listop.precipitants eq listop.precipant}">Selected </c:if>>${listop.precipitants}</form:option>       
                </c:forEach>
          </c:if>
 <form:option value="">-----------------------</form:option>
                <form:option value="Add New">Add New</form:option>
                <form:option value="removeP">Remove</form:option>
  </form:select>

&lt; --------在这里编辑----------&gt;

这就是我下拉的样子

enter image description here

点击&#34;添加新的&#34;它看起来像这样,但我想&#34; - 请选择 - &#34;相反&#34;添加新&#34; (见下图) enter image description here

我加上&#34; meme&#34;我的下拉列表看起来像这样

enter image description here

但我想这样 enter image description here

1 个答案:

答案 0 :(得分:2)

尝试此操作,根据需要修改条件。

    <form:select  name="precipant" path="precipant" id="precipant" onchange="showpopup(this.options[this.selectedIndex].value,this.form,'Newprecipant?#login_form3');">
 <form:option value="" selected="selected">--Please Select--</form:option> 

    <c:forEach items="${precipitantdroplist}" var="listop">
            <c:if test="${listop.precipitants eq listop.precipant}">
                <option value="${listop.precipitants}">${listop.precipitants}</option>
            </c:if>
            <c:if test="${listop.precipitants != listop.precipant}">
                <option value="${listop.precipitants}">${listop.precipitants}</option>
            </c:if>
    </c:forEach>

    <form:option value="">-----------------------</form:option>
    <form:option value="Add New">Add New</form:option>
    <form:option value="removeP">Remove</form:option>
</form:select>

或注册下拉列表的处理程序,如下所示,

<script type="text/javascript">

    $(document).ready(function() {

        $("#precipant").change(function() {
            $('select[name^="precipant"] option:selected').attr("selected",null);
            $('select[name^="precipant"] option[value="Please Select"]').attr("selected","selected");
        });

    });

    </script>
相关问题