I want to check if password input value is not equal to password 2 input value. Regardless of whether the passwords match it returns true.
html:
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<form class='login' name='form'>
<input id='pw' name='password' placeholder='Password' type='password'>
<input id='pw2' name='password2' placeholder='Password Again' type='password'>
<input class='animated' type='submit' value='Register'>
</form>
</body>
</html>
css:
.animated {
transition: background 0.3s ease-in-out;
}
.notEqual {
background-color: red;
}
jquery:
$( document ).ready(function() {
$('.animated').on('click', function (e) {
if ($('#pw'.value) != $('#pw2'.value)) {
e.preventDefault();
$(this).addClass('notEqual');
} else {
console.log("Passwords are equal");
}
});
});
JSBIN: http://ift.tt/1K48Gva
Thanks.
Aucun commentaire:
Enregistrer un commentaire