0
I have a script that returns me from the ID, the name and the checkbox Inactive, but even when someone marked as inactive my function does not return this field filled.
<script type='text/javascript'>
$(document).ready(function(){
$("input[name='id']").blur(function(){
var $nome = $("input[name='nome']");
var $inativo = $("input:checkbox[name='inativo']:checked");
$.getJSON('function_pes.php',{
id: $( this ).val()
},function( json ){
$nome.val( json.nome );
$inativo.val( json.inativo );
});
});
});
</script>
<!-- Fim do script de preenchimento automático dos campos a partir do campo ID -->
<form action="salvar_pessoa.php" method="post"><!-- Inicio Form -->
<div class="col-lg-2"><!-- Inicio Input ID -->
<label for="ex1">ID:</label>
<input type="text" class="form-control" maxlength="13" name="id">
</div><!-- Fim Input ID -->
<div class="col-lg-5"><!-- Inicio Input Nome -->
<label for="ex1">Nome:</label>
<input type="text" required class="form-control" maxlength="50" name="nome">
</div><!-- Fim Input Nome -->
<div class="col-lg-10"><!-- Inicio checkbox Registro Inativo-->
<div class="checkbox" style="margin-top:30px;">
<label>
<input type="checkbox" name="inativo" value="true" style="outline:none;">Registro Inativo
</label>
</div>
now returns all checkbox filled even if it has not been checked when registering
– user92870
Check your json if it’s not always dialing
true
or maybe thefalse
may be encoded in string https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean– Gabriel Chiquini
already solved the problem, thanks stayed this way the json => $inactive.prop('checked', !!+json.inactive); and this way I can return all my checkbox filled and differentiate from the ones that are not filled
– user92870