I am validating a form with the jQuery form validator plugin and am also submiiting the form via AJAX using jQuery click. Both of these work perfectly on their own but when I use both the click overrides the validation and the form doesn't validate
Any help on how to use these together gratefully received
Here is the code, the validation is not complete but does work
$(document).ready(function() {
$("#payment_details").validate({
rules: {
customerID: {
required: true
},
amount: {
required: true
}
}, //end rules
messages: {} //end messages
})
$("#createPayment").click(function() {
//alert("in function");
var customerID = $("#customerID").val();
var amount = $("#amount").val();
var paymentType = $("#payment_type").val();
var paymentDate = $("#payment_date").val();
var paymentMethod = $("#payment_method").val();
if (paymentMethod == "Cheque") {
var pbRef = $("#pb_ref").val();
} else {
var pbRef = "empty"
}
var staffMember = $("#staff_member").val();
// Returns successful data submission message when the entered information is stored in database.
var dataString = 'customerID=' + customerID + '&amount=' + amount + '&paymentType=' + paymentType + '&paymentDate=' +
paymentDate + '&paymentMethod=' + paymentMethod + '&pbRef=' + pbRef + '&staffMember=' + staffMember;
alert(dataString);
//AJAX code to submit form.
$.ajax({
type: "POST",
url: "createPayment.php",
data: dataString,
cache: false,
success: function(result) {
var paymentID = result;
alert(paymentID);
}
});
return false;
});
});