How To Stop Form Submit If The Validation Fails
UPDATE: my question is more about How to prevent the form submit if the validation fails the link does not solve my problem just re-iterate what I'm doing: I have a form with bunch
Solution 1:
You need to do two things if validation fails, e.preventDefault() and to return false.
For your example, with the input given, the pseudo code might be the next:
$("form").submit(function (e) {
var validationFailed = false;
// do your validation here ...if (validationFailed) {
e.preventDefault();
returnfalse;
}
});
Solution 2:
I able to fixed the problem:
First add the ref on your page:
<scriptsrc="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script><scriptsrc="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.min.js"></script>
then do this check:
$("form").submit(function () {
if ($(this).valid()) { //<<< I was missing this check
$("#loading").show();
}
});
Solution 3:
Write your validation code on onsubmit handler of your form like this
<formonsubmit="return Validation()"><inputclass="form-control"data-val="true"id="SerialNumber"name="SerialNumber"required="required"type="text"><buttontype="submit"name="rsubmit"class="btn btn-success">Submit</button><script>functionValidation(){
//Do all your validation here//Return true if validation is successful, false if not successful//It will not submit in case of false.returntrue or false;
}
</script></form>
Post a Comment for "How To Stop Form Submit If The Validation Fails"