In a ready table the users brought from a database, and to validate that a user is active or inactive, use a SWITCHE (on/off)
...
.done(function(rest) {
let resp = $.parseJSON(rest);
let output = '';
resp.map((e, key) => {
// Aqui valido si el usuario esta activo o inactivo
resp[key]['estado'] != 0 ? output = "<input type='checkbox' class='item' checked >" : output = "<input type='checkbox' class='item'>";
$('.tusers').append('<tr>
<td>${resp[key]['codigocurso']}</td>
<td>${resp[key]['nombre']}</td>
<td>${resp[key]['email']}</td>
<td>${resp[key]['id']}</td>
<td>
<div class='switch' onclick='idUser(${resp[key]['id']})'>
<label>
Inactivo
${output}
<span class='lever'></span>
Activo
</label>
</div>
</td>
<td><button class='btn waves-light red'>Eliminar</button></td>
</tr>');
})
})
function idUser(id){
let checked;
$(".item").change(function() {
if($(this).is(":checked")) {
checked = true;
}
else {
checked = false;
}
$.ajax({
url: 'http://localhost/conexion/controllers/HomeClass.php/updatestate',
type: 'POST',
data: {'id': id, 'checked' : checked}
})
.done(function(resp) {
console.log(resp);
})
.fail(function() {
console.log("error");
});
})
}
PROBLEM When I update the status of a user with the switch, I change the status of all users in different ways.
It can be seen that when changing a switche
changes the status of others in the script, how to validate the change of a single switch if it affects others?