I'm using an inline function to submit a form but it's not calling the validation script I have and I wondered if anyone could point me in the right direction of an answer?
My button:
<a href="javascript:UpdateEnquiry();" id="continue_btn" class="btnSprite">Save</a>
My Function:
function UpdateEnquiry() {
$.ajax({
url: 'test.php',
dataType: 'xml',
timeout: 15000,
type: 'post',
data: $('#validate').serialize(),
success: UpdateEnquirySuccess,
error: function (result) {parent.$.fancybox.close();}
});
}
And I would like to initialise the jquery validationEngine plugin before submit. http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/
Any help would be hugely appreciated.
Kind regards Rachel
Assuming your validation engine is already initialized, call the validate method before doing the ajax request. If that method returns true, you proceed:
function UpdateEnquiry() {
if ( $(yourForm).validationEngine('validate') ) {
$.ajax({
...
});
}
else {
// The form didn't validate
}
return false; // Prevents default action from happening
}
$('#registerform').submit(function(e) {
e.preventDefault();
var vars = $("#registerform").serialize();
if ($("#registerform").validationEngine('validate')) {
$.ajax({
url:"sample.php"
});
}
});
without stopping default action i was redirecting to my form action page. So had to use preventdefault(). @mgibsonbr my bad
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