0
It follows a simplified example of what I am doing. I need to check if the variables passed before and that would modify the Global are true in the checkbox.
$(document).ready(function() {
var usuario_ok;
$('#cadastro').on('keyup', 'input', function() {
var c_nome = $('#c_nome').val();
// Verificar Nome
if (c_nome.length > 2) {
var usuario_ok = true;
} else {
var usuario_ok = false;
}
//alert(usuario_ok);
});
$('#cadastro').on('change', '#c_concordo', function() {
var c_chk = this.checked ? true : false;
if (c_chk == true && usuario_ok == true) {
$('#deu_certo').html('OK');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="cadastro">
<input type="text" id="c_nome" />
<input type="checkbox" id="c_concordo">
</form>
<div id="deu_certo">Ainda não</div>
You are re-declaring the variable with
var usuario_ok
. You shouldn’t havevar
there.– Sergio