2
My script only works once, to make it work I have to give a report on the page.
This script below it checks if the passwords are different.
When I put a correct password in the first field and purposely a wrong one in the second, it will return me that the passwords do not match. the problem and when I put back the correct password it no longer performs the check only runs once the function as I can solve it
function validarSenha() {
NovaSenha = document.FormSenha.Password.value
CNovaSenha = document.FormSenha.CNovaSenha.value
if (NovaSenha == CNovaSenha) {
$("#status2").slideDown();
$("#status2").html(" Senha OK"); // abre minha div
$("#FormSenha").submit(function(){
return true;
});
setTimeout(function() { // fecha minha div
$("#status2").remove();
}, 5000);
return true
} else {
$("#status").slideDown();
$("#status").html(" A Segunda senha não confere");
// regra para não fazer o formulario enviar
$("#FormSenha").submit(function(){
return false;
});
setTimeout(function() { //
$("#status").remove();
}, 5000);
return false
}
}
//medidor de Senha forte
window.alert = function(){};
var defaultCSS = document.getElementById('bootstrap-css');
function changeCSS(css){
if(css) $('head > link').filter(':first').replaceWith('<link rel="stylesheet" href="'+ css +'" type="text/css" />');
else $('head > link').filter(':first').replaceWith(defaultCSS);
}
$( document ).ready(function() {
var iframe_height = parseInt($('html').height());
window.parent.postMessage( iframe_height, 'http://bootsnipp.com');
});
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<body class="login ">
<?echo $alert?>
<div id="status" style="display: none;
color: white;
height: 50px;
border-style: solid;
background-color: red;padding-left: 20px; padding-top: 8px; border-radius: 10px; font-size: 14px;">
</div>
<div id="status2" style="display: none;
color: white;
height: 50px;
border-style: solid;
background-color: green;padding-left: 20px; padding-top: 8px; border-radius: 10px; font-size: 14px;">
</div>
<br /><br />
<h2 style="text-align: center;"> Alterar Senha</h2>
<div id="login">
<div class="col-md-4"></div>
<div class="col-md-4">
<div class="wrapper"><br />
<div class="widget widget-heading-simple widget-body-gray">
<div class="widget-body">
<form method="POST" class="form" id="FormSenha" name="FormSenha" action="troca.php" >
<input type="hidden" name="ac" value="troc"/>
<input type="hidden" name="err" value="<?echo $id_user?>"/>
<input type="hidden" class="form-control" name="login" value="<?echo $login?>"/>
<input type="hidden" class="form-control" name="login" value=""/>
<label>Senha Antiga:</label>
<input type="password" class="form-control" maxlength="12" size="12" name="senha_antiga" placeholder="Senha" />
<label>Nova Senha:</label>
<input class="form-control" required="" id="Password" name="Password" data-val="true" data-val-length="Minimo 6 caracteres." data-val-length-max="100" data-val-length-min="6" data-val-required="password is required" placeholder="min 6 caracteres" maxlength="12" rows="12" type="password" />
<div id="pw-val-container">
<div id="pw-val-progress">
<div id="pw-val-verdict"></div>
<div id="pw-val-errors"></div>
</div>
<label>Repita a Senha:</label>
<input type="password" required="" class="form-control" maxlength="12" size="12" id="CNovaSenha" onblur="validarSenha()" name="senha2" placeholder="Repita" />
<a class="password" href="">Esqueceu sua senha?</a>
<div class="separator bottom clearfix"></div>
<div class="row">
<div class="col-md-8">
<button class="btn btn-block btn-inverse" onclick="validarSenha()" name="submit" type="submit">Alterar</button></div>
<div class="col-md-4 center"><button class="btn btn-block" style="background-color: #8080FF; color: white;" onblur="validarSenha()" name="submit" type="submit">Logar</button></div>
</div>
</form></div></div></div></div>
<div class="col-md-4">
</div>
<div class="col-md-2"></div></div>
</div></div>
Possible duplicate of Validate Fields and Form Submit
– Woss