I have two combo boxes. One combo box contain values that became variables to do AJAX post. The result then inserted into the second combo box.
I use
onchange
onload
$('#tl_dept').on('change', function() {
var dept_val = $(this).val();
var opsi = "";
var divs = "";
$.ajax({
type : "POST",
dataType : "json",
data : { x : dept_val },
context : $(this),
url : "<?php print base_url(); ?>xxx/some_function",
success : function(response){
//success script
}
});
});
I use onchange in the first combo box. However, I'd like to do it when body onload.
You do not need this.
You can use .trigger
function which executes all handlers and behaviors attached to the matched elements for the given event type.
$('#tl_dept').on('change', function() {
var dept_val = $(this).val();
var opsi = "";
var divs = "";
$.ajax({
type : "POST",
dataType : "json",
data : { x : dept_val },
context : $(this),
url : "<?php print base_url(); ?>xxx/some_function",
success : function(response){
//success script
}
});
}).trigger('change');