Reputation: 107
In my JSP page i'm using a popup to add new precipitants to the dropdown list. its working fine but problem is if i add one, the dorpdown shows "Add New" instead of "--Please Select--"
This is what i tried later
<c:if test="${listop.precipitants eq listop.precipant}">Selected </c:if>
and getting Unterminated <form:option tag
exception
here is my controller code
map.put("precipitantdroplist", bioprofileservice.listPrecipitantdrop());
map.put("Precipitantdropfam", new Precipitantsdrop());
and in 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>
<-------- edited here---------->
this is how my drop down look like
once i click "Add New" its look like this, but i want "--Please Select--" instead "Add New" (see the image below)
after i add "meme" my dropdown look like this
but i want like this
Upvotes: 2
Views: 4869
Reputation: 26067
Try this, modify if condition according to yours if required.
<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>
or register the handler for the dropdown like this,
<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>
Upvotes: 2