Salve a tutti!! Vi prego ho veramente bisogno di una mano col javascript: sto sviluppando un sito (ovviamente) che richiede la validazione dei vari campi di due form (login e signup) tramite l'evento onkeyup, in modo che esegue la funzione ogni volta che si scriva una lettera. Questo è il mio form:
e questo javascript:
Non riesco a capire per quale motivo non funzioni.
HTML:
<form method="post" action="login.php" name="login">
<div class="container_12">
<div class="box-white">
<p style="text-align: center">
<b style="font-size:25px">Login</b><br><br>
<input type="text" name="user_login" onkeyup="verify_pw()"><span id="us">Insert a Username</span>
<br><br>
<input type="password" name="pass_login" onkeyup="verify_pw()" id="pass"><span id="pw">Insert a Password</span>
<br><br>
<input type="checkbox" name="stay_logged" id="perma_login" checked>
<label for="perma_login" style="margin-left: -74px;"><b>Stay Logged</b></label>
<br><br>
<input type="submit" name="login" id="login" value="Login" class="button-orange">
</form>
</div>
<div class="box-white">
<form method="post" action="signup.php" name="signup">
<b style="font-size:25px">Signup</b><br><br>
<input type="text" name="email" onkeyup="verify_pw()">
<span id="em">Insert your e-Mail</span><br><br>
<input type="text" name="user" onkeyup="verify_pw()">
<span id="us">Insert a Username</span>
<br><br>
<input type="password" name="pass" onkeyup="verify_pw()" id="pass">
<span id="pw">Insert a Password</span>
<br><br>
<input type="password" name="ver_pass" onkeyup="verify_pw()" id="ver_pass">
<span id="pw_error">Verify the Password</span>
<br><br>
Bot verification:<br>
<img src="captcha.php" />
<input type="hidden" id="captcha" value="'.$stringa.'"><br><br>
<input type="text" id="ver_captcha" maxlength="5" style="width:80px;text-align:center" onkeyup="verify_pw()">
<span id="cap_error">Captcha verification (case-sensitive)</span><br><br>
<input type="submit" name="signup id="signup" value="Signup" class="button-primary" disabled>
<br><br>
</form>
</p>
<p style="text-align: center">
Designed and Developed by:<br>
<b>
<a target="_blank" href="http://www.facebook.com/dnviti">Daniele Viti</a>
(<a href="mailto:[email protected]">[email protected]</a>)
</b>
</p>
Codice:
<script type="text/javascript">
function verify_pw() {
var signupBtn = document.getElementById('signup');
//password control
var pass1 = document.getElementById('pass').value;
var pass2 = document.getElementById('ver_pass').value;
var pw_error = document.getElementById('pw_error');
if(pass1 == pass2){
signupBtn.disabled = false;
}else{
signupBtn.disabled = true;
pw_error.innerHTML = "<b style='color:red'>Passwords must be equal</b>";
}
//captcha control
var cap = document.getElementById('captcha').value;
var ver_cap = document.getElementById('ver_captcha').value;
var cap_error = document.getElementById('cap_error');
if(cap == ver_cap){
signupBtn.disabled = false;
}else{
signupBtn.disabled = true;
cap_error.innerHTML = "<b style='color:red'>Captcha do not match</b>";
}
}
</script>
Non riesco a capire per quale motivo non funzioni.