I have 2 select elements in my code. One for US states ( #us_state ) and one for cities ( #city_name ). When I select "state", the second select element should contain only those cities that exist in the selected state. I use ajax, I fulfilled the request and got a response. The response format is id: name {"26332":"Abbott Park","27350":"Addieville", ...}. Now I want to add an answer to the elements parameter and add it to select element c #city_name id. But I do not know how to achieve this result.<option value="key">value</option>
$('#us_state').bind('change', function() {
var projectId = $("#inputtitle").val();
var stateId = $(this).val();
var arrayData = {"projectId": projectId, "stateId":stateId};
$.ajax({
type: "GET",
url: "/bidboldly/projects/editproject/",
data: arrayData,
success : function(response) {
............
..........
},
error: function(){
alert("error");
}
})
});
source
share