2
I have 3 input, one type email and another type password:
<input id="usuario" type="email" placeholder="Usuário">
<input id="senha" type="password" placeholder="Senha">
And a Ubmit which will validate:
<input id="logar" type="submit" value="Entrar" class="enviar" onclick="return Redirecionar()">
I am trying to validate using a js file:
var botaoAdicionar = document.querySelector("#logar");
botaoAdicionar.addEventListener("click", function(event) {
var capturando = "";
function Redirecionar() {
capturando = document.getElementById('usuaario').value;
capturando = document.getElementById('senhaa').value;
document.getElementById('capturando').innerHTML = capturando;
if (usuario == "[email protected]" && senha == "123") {
function Redirecionar() {
window.location.href="menu.html";
}
}
else{
alert("Dados incorretos! Por favor, tente novamente.");
}
}
});
However the page just updates, already in several ways and I can’t :/ So who can help me :) I appreciate
Adds
event.preventDefault();
at the beginning of the click function, to avoid updating the page. You can also change thetype="submit"
fortype="button"
.– Benilson
You are calling a function that is within the function of the click event and declared the same function 2 times, one inside the other. In addition to other problems, such as declaring the variable
capturando
2 times with different values. You have to redo the code.– Sam
Oh yes, I had already put this line, but I ended up removing it unintentionally as I tried. Unfortunately this is not the problem.
– Jonatan
Also has typos in "usuaario" and "senhaa".
– Benilson
I get it, so it’s unnecessary for me to use two functions for this case, right?
– Jonatan
Yes, they were already correct in the original file, as I said I had already made several modifications and I ended up sending an old one without the proper corrections.
– Jonatan
If you add the Event Listener no JS, does not make sense the
onclick="return Redirecionar()"
on the button. Also you are creating functions within the callback that are not used. Need to give a studied in JS scopes and events, here at Sopt has enough related content– Costamilam
Thank you !!!!! worked out well
– Jonatan