I’m doing it this way so the checkbox stays checked if the database value is returned
$(document).on('click', '.upd_glic', function(){
var id = $(this).parents("tr").attr("id");
$.ajax({
url:"editarglic.php",
method:"POST",
cache: false,
data:{id:id},
dataType:"json",
success:function(data){
for (var i = 0; i < data.length; i++) {
Id = data[i][0];
Validar = data[i][6];
$('#idgli').val(Id);
$('#validart1').prop('checked', Validar);
}
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#" class="dropdown-item btn btn-warning upd_glic"><i class="metismenu-icon pe-7s-note"></i> Alterar</a>
<form method="POST" class="row g-3 insgli1">
<input type="hidden" class="form-control" name="idgli" id="idgli">
<div class="col-md-4 valt">
<div class="form-group checkbox">
<input type="checkbox" id="validart1" name="validart1" value="Sim">
<label for="validart1"> Realizada correção com insulina após pesquisa</label>
</div>
</div>
</form>
I already checked and it returns the value of the database, but the checkbox is never checked.
Can you help?