Reputation: 731
Please be easy with me, I am trying to solve but could not hence asking for help. I have 2 combo boxes named as first combo box and second combo box in auto.jsp.
I am getting value in a div in auto.jsp by onchange event of first combo box, but the value, i am getting is not populating in the second combo box rather it is being displayed like plain text inside the id combo2
. How to populate this data with in that second combo box. I tried a lot but could not do it , any ideas please?
<script type="text/javascript">
$(document).ready(function() {
$("#combo1").change(function() {
$.get('combo.jsp', { combo1Val : $(this).val() }, function(responseData) {
$("#combo2").replaceWith(responseData);
});
});
});
</script>
<body>
<select id="combo1" name="combo1Val">// After onchange event of this combo box, second box is disappeared and i am getting value 1, how can i display this one inside the option value of second combo box?
<option value="">select</option>
<option value="1">One</option>//
</select>
<select id="combo2" name="combo2">
<option value="">select</option>
<option value="2">Two</option>
</select>
</body>
<%
String combo1Val=request.getParameter("comboVal");
out.println(combo1Val);// displaying value 1 in auto.jsp in id combo2
%>
Any ideas please?
Upvotes: 1
Views: 1315
Reputation: 150030
Try replacing this line:
$("#combo2").replaceWith(responseData);
With something like this:
$("#combo2").append(
$("<option></option>").html(responseData).val(responseData)
);
That should add a new option to the end of the second combo, where both the display text and the value
attribute will be set to responseData
(since you're not returning separate values for those).
http://www.htmlgoodies.com/primers/jsp/
Upvotes: 1