Dont submit the form after jquery validation
I have a form which have the jquery validation. My problem is, I just want to validate the form and I dont want to submit. How to do that?
Any suggestion开发者_运维问答s?
Thanks in advance.
If you want it to happen in the submit button, do:
$("#your_form").submit(function(event){
event.preventDefault();
});
But if you want to validate by scripting anytime, do:
//Validates but doesn't submit. Validates and returns true or false indicating if it was valid.
$("#form").data('validator').form();
Hope this helps. Cheers
Try to bind "valid()" function to an event wich does't send the form.
$('#yourbutton').click(function(){
$("#yourform").valid();
});
$(document).ready(function(e){
$('#submit').submit(function(e){
//validate form
e.preventDefault(); // or return false ;
});
});
If you are using the jQuery Validation plugin, pass onsubmit: false
to the validate method:
$('#someForm').validate({
onsubmit: false
});
精彩评论