I'm trying to add a custom validation method to the jquery-validation plugin. With given countrycode, zip and city, i call a php-script via ajax to check if this combination exists and if so, it gives back a "valid".
So my added method looks like this:
jQuery.validator.addMethod("zipcitycombination", function(city, element, params) {
//function check zip and city
var country = params[0];
var zip = params[1];
$.ajax({
type: 'GET',
url: '/?eID=tx_zipcity',
async: false,
data: 'country=' + country + '&zip=' + zip+ '&city=' + city,
success: function(data){
response = ( data == 'valid' ) ? true : false;
}
})
return response;
}, "Please check your combination");
And now i try to use the validation like this:
$("#commentForm").validate({
rules: {
delivery_city: {
zipcitycombination:[$('select[name="amsdelivery_country"]').val(),$('input#delivery_zip').val()]
}
}
So everything works fine, except the zipcitycombination:
[$('select[name="delivery_country"]').val(),$('input#delivery_zip').val()],
because it uses the empty values and not the values from the filled out input fields. Setting the values already in the html-file, the validation works as expected...