Hi, I already received a lot of help when I needed a select field to fill in automatically in this post here: fill javascript / jquery select field
It's working perfectly well, but now I need to open a page where the select field is already filled, the second select field automatically pops up as well, but it's only filling the moment I click and select something in my first field select.
Here is the javascript code that fills the select (I need it to populate when I open the page, and a "selected" value will come from the database, not just when I select something)
$(document).ready(function() {
$('#cSecretaria').on('change', function(){
$.post('http://siscpd.com/_require/_jp/jpcarregasetor.php',
{
id_sec: document.getElementById("cSecretaria").value,
},
function (res) {
$('#cSetor').html(res).selectpicker('refresh');
}
)
})
})