I am displaying a checkbox in a modal dialog. I use ajax to retrieve a database model with one of the variables returned being data.admin. When this variable equals the string "A" the checkbox must be shown as checked. Otherwise it should remain unchecked.
Below is my code:
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="admin" name="admin">
<label class="custom-control-label" for="admin">Admin</label>
</div>
$(document).on('click', '.edit_data',function(){
var id_code = $(this).attr("id");
$.ajax({
url:"edit.php",
method:"post",
data:{id_code:id_code},
datatype:"json",
success:function(data){
$('#code').val(data.code);
$('#login').val(data.login);
$('#pass').val(data.pass);
$('#admin').val(data.admin);
$('#id_code').val(data.id);
$('#myModale').modal("show");
}
});
});