I’m trying to do initial validation before using $.ajax() call (where additional validation is performed) to save on calls to the server. Currently I’m using the following :
$('.form_submit').submit(function() {
var frm = $(this);
var url = frm.attr('action');
var data = $(this).serializeArray();
var proceed = true;
$.each(data, function(index, value) {
var name = data[index].name;
if ($('#' + name).hasClass('required') && value == '') {
$('.label_' + name).append('Please provide the value');
proceed = false;
}
});
if (proceed) {
$.ajax({
but the value of the ‘proceed’ variable doesn’t seem to be taken under consideration and the validation goes straight to ajax.
Any help would you much appreciated.
I’ve figured out how to achieve it and add support for all other fields as well (such as radio buttons, textareas etc.) – here’s what I’ve come up with:
I’ve assigned the validation message to the ‘title’ attribute of the ‘input’ field – so that you can have a different one for each tag. With radio buttons – simply add ‘title’ to the first button.