Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery validation: prevent form submit

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?

like image 931
alex Avatar asked Apr 24 '12 21:04

alex


People also ask

How to prevent a form from submitting in jquery?

We use the preventDefault() method with this event to prevent the default action of the form, that is prevent the form from submitting.

How do you stop form submit if the validation fails?

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.

How to stop form submit in html?

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.


1 Answers

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; } 
like image 129
The Alpha Avatar answered Sep 21 '22 10:09

The Alpha