By the use of the jQuery plugin Validation, I am trying to, well, validate my form. When the validation passes, I want a javascript to fire with values from the form and then stop. no actual form submission with browsing to a new/same site.
is this possible with jquery validation?
We use the preventDefault() method with this event to prevent the default action of the form, that is prevent the form from submitting.
Use the return value of the function to stop the execution of a form in JavaScript. False would return if the form fails to submit.
The simplest solution to prevent the form submission is to return false on submit event handler defined using the onsubmit property in the HTML <form> element.
You may try this (Example):
$(function(){ $("#myform").validate(); $("#myform").on('submit', function(e) { var isvalid = $("#myform").valid(); if (isvalid) { e.preventDefault(); alert(getvalues("myform")); } }); }); function getvalues(f) { var form=$("#"+f); var str=''; $("input:not('input:submit')", form).each(function(i){ str+='\n'+$(this).prop('name')+': '+$(this).val(); }); return str; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With