---
title: "jquery: prevent form submit on ajax validation error"  
description: "jquery: prevent form submit on ajax validation error"  
author: "Anonymous User"  
published: 2013-02-16  
updated: 2013-02-18  
canonical: https://www.mindstick.com/forum/608/jquery-prevent-form-submit-on-ajax-validation-error  
category: "ajax"  
tags: ["ajax"]  
reading_time: 1 minute  

---

# jquery: prevent form submit on ajax validation error

Hi MindStickians!

I have a form with some ajax [validation](https://www.mindstick.com/articles/12234/validation-using-data-annotation-using-entity-framework) [fields](https://www.mindstick.com/forum/159126/sql-query-for-all-tables-and-fields-in-an-oracle-db).(not all fields are validated using ajax)

I want to prevent form submit if there is an [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) on one of those fields.

I would like it to be generic for other [forms](https://www.mindstick.com/interview/34192/what-is-the-purpose-of-the-authentication-mode-forms-element-in-web-config) I have with ajax validation.

1 flag would not do the trick.

This is what the ajax [field](https://www.mindstick.com/forum/160867/does-mindstick-provide-training-for-field-marketing) looks like on error:

<[label](https://www.mindstick.com/articles/12835/print-label-tracking-how-do-these-features-make-auspost-woocommerce-plugin-better) id="id_name_lab" [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp)="error">name</label>\
<[input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) id="id_name" type="text" maxlength="128" name="name">\
<label id="id_name_succ_icn" class="icon_succ" [style](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment)="display: none;"></label>\
<label id="id_name_load_icn" class="icon_load" style="display: none;"></label>

Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Goti!\
you can try this way\
$("form").one( "submit", function() { var self = this; // ajax validation $.ajax() .done( function() { // call validation, if form is valid, ajaxValidation calls submit again. ajaxValidation( self ); });

// first submit is always ignored.

e.preventDefault();

return false;

});

function ajaxValidation( target ) {

// check valid & call submit

}


---

Original Source: https://www.mindstick.com/forum/608/jquery-prevent-form-submit-on-ajax-validation-error

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
