1
I am having the following problem, I am trying to change the action of the form using the following function, what happens is that if the condition is false for any of them the same still tries to execute all others trying to execute all the conditions.
function testando(resultado) {
var nomesconsu = null;
var nomecampo = document.getElementById("conMarPac").value;
$.post("/comparar", function(nomescon) {
for (i = 0; i < nomescon.length; i++) {
if (nomecampo == nomescon[i].nome) {
nomesconsu = nomescon[i].nome;
}
}
});
if (nomecampo !== nomesconsu && resultado === 'marcar') {
$('#marCon').attr('action', '/profile');
console.log(nomesconsu);
console.log(nomecampo);
console.log('entrou no profile');
return;
} else if (nomecampo === nomesconsu && resultado === 'marcar') {
$('#marCon').attr('action', '/incon');
console.log('entrou no incon');
return;
} else if (resultado === 'salvar') {
$('#marCon').attr('action', '/salvar');
alert("salvo");
}
}
I haven’t been able to solve the problem yet, thanks anyway
– Theogenes Nunes
Put your code on jsfiddle.net
– Eduardo Abreu dos Santos