Set combobox value using jquery | Populate dropdown list box
To change the value of the combobox based on the selection in the drop down, this should do the trick:
$("#combobox").change(function() {
var curVal=$(this).val();
$("#combobox").combobox("autocomplete",curVal);
});
There needed to be a function to handle the change of the combobox select field. On change it will run the combobox function with the autocomplete value of the currently selected option in #combobox.
Let's take another example to populate listbox2 on change event of listbox1 using ajax post:
Following code will be written in jquery or java script file. Assume that you have two list box in your html form
$(document).ready(function(){
$("#listbox1").on("change", function(event){
var listbox1_code = $("#listbox1").select2().select2("val");
$.post("url_path/get_list.php?code="+listbox_code_1, function(data) {
if(a_sub_type == ''){
$("#listbox2").empty(); //to clear listbox2
$("#listbox2").select2().select2("val", ''); //show empty text i.e. 'Select One'
$("#listbox2").select2(); //for refresh listbox...
} else {
$("#listbox2").select2().select2("val", 'Select One');
$("#listbox2").html(data);
$("#listbox2").select2(); //for refresh list...
}//end of else if part...
}); //end of ajax post....
}); //end of listbox_1 change event...
}); //end of document ready event...
If you have any query regarding this please let me know.
Let's take another example to populate listbox2 on change event of listbox1 using ajax post:
Following code will be written in jquery or java script file. Assume that you have two list box in your html form
$(document).ready(function(){
$("#listbox1").on("change", function(event){
var listbox1_code = $("#listbox1").select2().select2("val");
$.post("url_path/get_list.php?code="+listbox_code_1, function(data) {
if(a_sub_type == ''){
$("#listbox2").empty(); //to clear listbox2
$("#listbox2").select2().select2("val", ''); //show empty text i.e. 'Select One'
$("#listbox2").select2(); //for refresh listbox...
} else {
$("#listbox2").select2().select2("val", 'Select One');
$("#listbox2").html(data);
$("#listbox2").select2(); //for refresh list...
}//end of else if part...
}); //end of ajax post....
}); //end of listbox_1 change event...
}); //end of document ready event...
If you have any query regarding this please let me know.
Set combobox value using jquery | Populate dropdown list box
Reviewed by Ashok Sen
on
00:43:00
Rating:
No comments:
Post a Comment