Reputation: 33
I am trying to validate the password match while typing however, its not working can someone please tell me the error
Here is the code
<!DOCTYPE html>
<html>
<head>
<title>password change </title>
<script>
$(document).ready(function () {
$("#txtConfirmPassword").keyup(checkPasswordMatch);
});
function checkPasswordMatch() {
var password = $("#txtNewPassword").val();
var confirmPassword = $("#txtConfirmPassword").val();
if (password != confirmPassword)
$("#divCheckPasswordMatch").html("Passwords do not match!");
else
$("#divCheckPasswordMatch").html("Passwords match.");
}
</script>
</head>
<body>
<div class="td">
<input type="password" id="txtNewPassword" />
</div>
<div class="td">
<input type="password" id="txtConfirmPassword" />
</div>
<div class="registrationFormAlert" id="divCheckPasswordMatch">
</div>
</body>
</html>
Upvotes: 0
Views: 447
Reputation: 929
You have to include a reference to JQuery in order to use it.
<!DOCTYPE html>
<html>
<head>
<title>password change </title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#txtConfirmPassword").keyup(checkPasswordMatch);
});
function checkPasswordMatch() {
var password = $("#txtNewPassword").val();
var confirmPassword = $("#txtConfirmPassword").val();
if (password != confirmPassword)
$("#divCheckPasswordMatch").html("Passwords do not match!");
else
$("#divCheckPasswordMatch").html("Passwords match.");
}
</script>
</head>
<body>
<div class="td">
<input type="password" id="txtNewPassword" />
</div>
<div class="td">
<input type="password" id="txtConfirmPassword" />
</div>
<div class="registrationFormAlert" id="divCheckPasswordMatch">
</div>
</body>
</html>
Upvotes: 1