I have a ComboBox that loads the option from the database.
I need that when selecting any data, load the query, depending on the selected option, all this with AJAX.
I have a ComboBox that loads the option from the database.
I need that when selecting any data, load the query, depending on the selected option, all this with AJAX.
I recommend using onchange
.
<select onchange="myFunction()">
Then capture the value of the select
(ComboBox) and use the AJAX in the function assigned to onchange
.
Add an ajax function in the onclick
event. You pass, for example, the id of the element that you have selected to be able to make the query in the database.
elemento.addEventListener('click',function(event){
llamarAjax(event.id);
});
You could join the change event of the combo and there make the ajax call
<script>
$(function(){
$("#comboId").change(function(){
var seleccion = $(this).val();
$.ajax({
type: "POST",
url: "url",
data: seleccion,
datatype: "application/json",
success: function (data) {
$('#result').html(data);
}
});
});
});
</script>
In this case I use jquery to control the event and also invoke the server through ajax