1
Guys, I tried to make this fiddle to understand how to compare conditions of elements with javascript, but I don’t know what went wrong.
var username = "admin";
var password = "admin";
function validarUsuarioSenha() {
if ($("#usuario").value() == username && $("#senha").value() == password) {
$("#loginCorreto").show();
} else {
$("#loginErrado").show();
}
}
#loginCorreto {
width: 235px;
height: 20px;
background: green;
color: #FFFFFF;
display: none;
}
#loginErrado {
width: 235px;
height: 20px;
background: red;
color: #FFFFFF;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="usuario" type="text" placeholder="Digite seu login: " />
<br/>
<br/>
<input id="senha" type="password" placeholder="Digite sua senha: " />
<br/>
<br/>
<input type="button" value="Fazer login" onclick="validarUsuarioSenha()" />
<br/>
<br/>
<div id="loginCorreto">Login efetuado com sucesso!</div>
<div id="loginErrado">Usuário ou senha inválidos!</div>
It worked, buddy... but what you’ve changed besides ". val()"?
– Israel Sousa
The function
validarUsuarioSenha
must be declared before being referenced on the button. Then include it in the <head> preference.– Marcus Vinicius