This is very important for registration.I have used onKeyUp() to check password/confirm are same. and get values using document.getElementById('') function.
Please share your comments and feedback.Thanks.Please subscribe my updates via email.
JQuery Function
<script>
function checkPasswords()
{
var password1 = document.getElementById('password1');
var password2 = document.getElementById('password2');
var message = document.getElementById('alertMessage');
var goodColor = "#66cc66";
var badColor = "#ff6666";
if(password1.value == password2.value){
password2.style.backgroundColor = goodColor;
message.style.color = goodColor;
message.innerHTML = "Passwords Match!"
}else{
password2.style.backgroundColor = badColor;
message.style.color = badColor;
message.innerHTML = "Passwords Do Not Match!"
}
}
</script>
function checkPasswords()
{
var password1 = document.getElementById('password1');
var password2 = document.getElementById('password2');
var message = document.getElementById('alertMessage');
var goodColor = "#66cc66";
var badColor = "#ff6666";
if(password1.value == password2.value){
password2.style.backgroundColor = goodColor;
message.style.color = goodColor;
message.innerHTML = "Passwords Match!"
}else{
password2.style.backgroundColor = badColor;
message.style.color = badColor;
message.innerHTML = "Passwords Do Not Match!"
}
}
</script>
HTML
<form>
<div class="fieldWrapper"> Password:
<input type="password" name="pass1" id="password1">
Confirm Password:
<input type="password" name="pass2" id="password2" onKeyUp="checkPass(); return false;">
<span id="alertMessage" class="alertMessage"></span> </div>
</form>
<div class="fieldWrapper"> Password:
<input type="password" name="pass1" id="password1">
Confirm Password:
<input type="password" name="pass2" id="password2" onKeyUp="checkPass(); return false;">
<span id="alertMessage" class="alertMessage"></span> </div>
</form>
No comments:
Post a Comment