0
I have a code and in it I have a Javascript (which was passed by the teacher); this code is a form and I need to validate the informed passwords.
However, I am putting equal passwords and also different passwords and do not see any information - if it is identical passwords, registered done; if it is different, different passwords - someone could help me?
function validarSenha() {
var senha1 = document.getElementById("senha");
var senha2 = document.getElementById("senhaTmp");
var s1 = senha1.value;
var s2 = senha2.value;
if (s1 == s2) {
alert("Dados Cadastrados");
return true;
} else {
alert("Senhas não batem. Verifique o valor digitado.");
return false;
}
}
<fieldset>
<legend>Formulário:</legend>
<form id="cad">
<label for="nome">Digite seu nome:</label><br>
<input type="text" name="nome" pattern="[A-Z][a-z]+[ ][A-Z][a-z]+"><br>
<label for="idade">Idade:</label><br>
<input type="date" name="idade"><br>
<label for="cpf">CPF:</label><br>
<input type="text" name="cpf" pattern="[0-9]{3}[.][0-9]{3}[.][0-9]{3}[-][0-9]{2}"><br>
<label for="cep">CEP:</label><br>
<input type="text" name="cep" pattern="[0-9]{2}[.][0-9]{3}[-][0-9]{3}"><br>
<label for="email">Digite seu email:</label></br>
<input type="email" name="email" pattern="[^. ][A-Za-z0-9.]*[^. ][@][A-Za-z0-9.]*[^. ]" /><br>
<label for="senha">Digite sua senha:</label><br>
<input type="password" name="senha" pattern="[^. ][A-Za-z0-9.]*[^. ][@][A-Za-z0-9.]*[^. ]" /><br>
<label for="senhaTmp">Confirme sua senha:</label><br>
<input type="password" name="senhaTmp" pattern="[^. ][A-Za-z0-9.]*[^. ][@][A-Za-z0-9.]*[^. ]" /><br>
<input type="reset" name="limpar" /><br>
<input type="submit" onclick="return validarSenha()" value="Cadastrar" /><br>
</form>
</fieldset>
You are using
getElementById
but no element hassenha
orsenhaTmp
defined as theirid
, is asname
.– Diego Rafael Souza
Really @Diegorafaelsouza thanks was wrong on that part.
– Igor Pompeo
Your regular expressions for passwords and email are the same?
– jean