I have a password and confirm password field like below.enter image description here
I have used the same elements and script in 2 other different forms, but it isn't working in one of the forms.
Password: <input id="pwd" name="pwd" type="password"><br><br>
Conform Password: <input id="cpwd" name="cpwd" type="password">
<div id="errorMsg"></div>
<script>
var password = document.getElementById('pwd');
confirm_password = document.getElementById('cpwd');
function validatePassword() {
if ((confirm_password.value!='')&&(password.value != confirm_password.value)) {
document.getElementById('errorMsg').innerHTML='Passwords Don\'t Match';
} else {
document.getElementById('errorMsg').innerHTML='';
}
}
password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;
</script>