How to redirect page on Jquery validation success [duplicate]
I am using jquery for validation set some rules.
If validation success I want to redirect to another page. How can I do it?
// validate contact form on keyup and submit
$("#contactForm").validate({
//set the rules for the field names
rules: {
name: {
required: true,
minlength: 2
},
email: {
required: true,
email: 4
},
},
//set messages to appear inline
messages: {
name: "Please enter your name",
password: "Please enter your email"
}
});
Add your redirect logic in submitHandler
callback. I think you want to set the window.url
to a diff url. right?
Call window.location.replace='http://www.newpage.com';
. Not jQuery specific.
Try adding a submitHandler
option to validate
like so:
$("#contactForm").validate({
...
submitHandler: function(form) {
window.location = "http://your.url.here";
}
});
So when you validate the form, submitHandler
is called if the form validated successfully, and there you redirect the user.
精彩评论