bootstrap-combobox
bootstrap-combobox copied to clipboard
How to bind second combobox on the basis of first combobox selected value
trafficstars
How to bind second combobox on the basis of first combobox selected value I have two combo boxes 1)Country 2)State for the selecttion of country i need to bind states I have assign the datasource using ajax, i can see the options present in the hidden select element but actual visible input does not showing ui li tags for options present in second combobox
This is how I am doing something similar but with categories and then products.
$('#product-select').combobox();
$('#category-select').on('change', function(){
$('#product-select').html('<option value=""></option>');
$('.combobox-container').removeClass('combobox-selected');
var category = $(this).val();
$.ajax({
url: 'getProducts',
data: {'category':category},
success: function(data) {
if(data.success){
//Append all of the elements
$.each(data.units, function(i, v){
$('#product-select').append('<option value="'+v.id+'">'+v.name+'</option>');
});
//Empty the previous selection, refresh the comobox box and perform a lookup
$('.combobox-container input.combobox').focus().val('').removeAttr('placeholder');
$('#product-select').combobox('refresh');
$('#product-select').combobox('lookup');
}
},
error: function() {
alert("There was an error preventing your message from being sent. Please try again.");
}
});
});