In my HTML it has the following line:
<label class="turnoCurso pretoClaro" id="3"> Vespertino, Noturno </label>
I need to transform the shifts that are brought from the database into an array and for this I use the following code:
var turnoLista = $('#'+id+'.turnoCurso').text().trim();
turnoLista = turnoLista.split(",")
And so far so good, the problem is to leave the checkbox as checked it just marks the first item and ignores the others, follow the code I'm using
$(turnoLista).each(function(indice, valor){ //
switch(valor)
{
case "Vespertino":
$("#turnoV").prop('checked',true);
break;
case "Matutino":
$("#turnoM").prop('checked',true);
break;
case "Noturno":
$("#turnoN").prop('checked',true);
break;
case "EAD":
$("#turnoE").prop('checked',true);
break;
}
});
Checkbox:
<input id="turnoM" type="checkbox" name="turno" value="1"> Matutino
<input id="turnoV" type="checkbox" name="turno" value="2"> Vespertino
<input id="turnoN" type="checkbox" name="turno" value="3"> Noturno
<input id="turnoE" type="checkbox" name="turno" value="4"> EaD
What happens is that the code just leaves the first chebox checked and if you put an alert inside the each it can detect all the indexes of the vector correctly, would anyone know how to help me?
I'm using a JS that is embedded in the page via an Ajax request and so I can not debug JS.