I am using the datatable with ajax, getting among others a column with select, but I do not know why onchange
does not work. Here's the ajax return:
{"data":
[[
1,
"17020161",
"Marina Costa Vasconcelos",
"<select data-id='17020161' id='status_aluno17020161' style='background-color: #00C851; color:white' class='form-control status' ><option style='background-color: #00C851; color:white' value='1' >Presente<\/option>\n<option style='background-color: #ff4444; color:white' value='2'>Falta<\/option><\/select>",
"",
"",
""
],[
2,
"12080243",
"Talita de Souza Menezes",
"<select data-id='12080243' id='status_aluno12080243' style='background-color: #00C851; color:white' class='form-control status' ><option style='background-color: #00C851; color:white' value='1' >Presente<\/option>\n<option style='background-color: #ff4444; color:white' value='2'>Falta<\/option><\/select>",
"",
"",
""
]]
}
In this the following function does not work:
$(document).ready(function() {
$('.status').on('change', function() {
//$(".status").change(function(){
var valor = this.value;
var matricula = $(this).data("id");
alert(matricula);
alert(valor);
if (valor == 1) {
$("#status_aluno"+matricula).css("background-color", "#00C851");
}
if (valor == 2) {
$("#status_aluno"+matricula).css("background-color", "#ff4444");
}
if (valor == 3) {
$("#status_aluno"+matricula).css("background-color", "#00C851");
}
if (valor == 4) {
$("#status_aluno"+matricula).css("background-color", "#ffbb33");
}
if (valor == 5) {
$("#status_aluno"+matricula).css("background-color", "#ffbb33");
}
if (valor == 6) {
$("#status_aluno"+matricula).css("background-color", "#ff4444");
}
}
);
});