xxxxxxxxxx
1
<div class="col-md-5 mb-0">
2
<div>
3
<select name="fc_funcao" id="fc_funcao" class="mdb-select colorful-select dropdown-warning" data-visible-options="10" searchable="Buscar...">
4
<option value="" disabled selected>Função</option>
5
</select>
6
</div>
7
</div>
8
1
1
xxxxxxxxxx
1
2
3
4
$("#fc_setor").on("change",function(){
5
6
var select = document.getElementById('fc_setor');
7
var option = select.options[select.selectedIndex];
8
9
document.getElementById('id_setor2').value = option.value; // mostra o id do value do select do setor
10
document.getElementById('id_setor').value = option.text; // mostra o texto do value do select do setor
11
12
//quando seleciona um option salva dentro da veriavel
13
var $id_setor2 = document.getElementById('id_setor2').value = option.value;
14
var $id_setor = document.getElementById('id_setor').value = option.text;
15
//alert ($id_setor2);
16
17
var id_setor2 =$('#fc_setor').val(); // esse mostra o numero do ID setor
18
var id_setor =$('#id_setor').val(); // esse mostra o nome do setor
19
alert(id_setor2);
20
console.log(id_setor2);
21
22
23
$.ajax({
24
url: '../dados/consultar_funcao.php',
25
type: 'GET',
26
dataType: 'JSON',
27
data: {id_setor2:id_setor2, id_setor:id_setor},
28
})
29
.done(function(data) {
30
alert(data);
31
console.log(data);
32
33
34
var html = '';
35
for (var count = 0; count < data.length; count++){
36
html += '<option value="' + data[count] + '">' + data[count] + '</option>';
37
}
38
alert(html);
39
console.log(html);
40
41
42
//from that point on it doesn't work, it doesn't load the options coming from the query inside the select
43
44
$('#fc_funcao').val(html);
45
46
// ------------------------------------------------
47
48
49
50
})
51
.fail(function() {
52
console.log("error");
53
})
54
.always(function() {
55
console.log("complete");
56
});
57
58
59
60
});
61
Console errors: 0