
I am fetching some data from database and want to show these values in a combo in javascript but combo box is not populating any value, perhaps i am doing something wrong in json or javascript, can anybody tell me where i am wrong? From db 5 values are coming in while loop
JSONObject jsonObj= new JSONObject();
List<String> myList = new ArrayList<String>();
while(rs.next()){
t1=rs.getString(1);
myList.add(t1);
jsonObj.put("name",myList.toArray());
}
response.setContentType("application/json");
response.getWriter().write(jsonObj.toString());
want to get above values in javascript
<script type="text/javascript">
$(document).ready(function() {
$("#combo").change(function() {
$.getJSON('combo.jsp', {count : this.value}, function(responseData) {
$("#combo1").empty().append ("<option>please select</option>");
var json = $.parseJSON(responseData);
var myValues = json.name;
for (var idx in myValues) {
$("#combo1").append(
$("<option></option>").html(myValues[idx]).val(myValues[idx])
);
}
});
});
</script>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.