I would like to check (into a jsp page) whether the values of password1 & password2 are equal or not. And if they are not equal, it will stay on the same page. Otherwise it will update. I could do all things but I am unable to make the form to stay on the same page if the passwords are not equal. the codes which i tried are like the following:
<form id="form1" method="post" action="saveUpdatePassword">
Password: <s:password name="password1" id="password1" />
Re-type password: <s:password name="password2" id="password2" />
<input type="submit" id="sumbitButton" value="Update" />
</form>
$(function() {
$("#sumbitButton").click(function() {
if ($("#password1").val() != $("#password2").val()) {
alert("Not equal");
}
});
});
Can you tell me how to make the form staying on the same page if the password does not match? And provide users to put the password again?
You are looking for event.preventDefault()
$(function() {
$("#sumbitButton").click(function(event) {
if ($("#password1").val() != $("#password2").val()) {
alert("Not equal");
event.preventDefault();
}
});
});
Note the event
parameter being passed into the click handler.