0
I’m having a problem, I want before giving Submit to run validation();
<div class="nova-conta">
<h2>Cadastre-se</h2>
<form onsubmit="validarsenha()" method="POST" action="cadastro.php" name="novocadastro" >
<div class="form-group">
<label for="email" class="control-label">E-mail:</label>
<input type="email" name="f_email" placeholder="Digite seu E-mail" class="form-control" id="email" data-error="Por favor, informe um e-mail correto." required>
</div>
<div class="form-group">
<label for="senha" class="control-label">Senha:</label>
<input type="password" name="f_senha" placeholder="Digite sua Senha" class="form-control" id="f_senha" size="20" required>
</div>
<div class="form-group">
<label for="senha" class="control-label">Repita a senha:</label>
<input type="password" name="f_senhaconfirma" placeholder="Confirme Senha" class="form-control" id="f_senhaconfirma" size="20" required>
</div>
<div id="btn-conta">
<a href="Index.html" class="btn btn-default"> Cancelar</a>
<button type="submit" onclick="return validarsenha()" class="btn btn-primary">Cadastrar</button>
</div>
</form>
</div>
Remembering what I’m calling this function
function validarsenha(){
var senha=novocadastro.f_senha.value;
var rep_senha=novocadastro.f_senhaconfirma.value;
if(senha == "" || senha.length < 5){
alert (`Preencha o campo senha com no minimo 6 caracteres`)
novocadastro.f_senha.focus();
return false;
}
if(rep_senha == "" || rep_senha.length < 5){
alert (`Preencha o campo confirma senha com no minimo 6 caracteres`)
novocadastro.f_senhaconfirma.focus();
return false;
}
if(senha != rep_senha){
alert (`As senhas sao diferentes!`)
novocadastro.f_senhaconfirma.focus();
return false;
}
}
He is always going to PHP, and does not execute the validate function. Anyone knows how I can solve this problem of mine?
The code is working... at least in Chrome. The way in which you are capturing the elements of the DOM is depreciated, and has no guarantee that it will work in all browsers. Try to use
var senha = document.getElementById('f_senha').value;
– Andre
Put it on the Chrome console to preserve LOG, so try to commit, it is very likely that you have some script error elsewhere/script.
– Guilherme Nascimento