I am attempting to create a simple validation function for my contact form.
Click here At the moment, once details are submitted the form keeps display:none even when entries are incorrect. I have tried to target the form id Which doesn't seem to be working either.
below is a snippet of my function
var form = $('#ajax-contact');
var formMessages = $('#form-messages');
form.validate();
$(form).submit(function(e) {
if ($('#ajax-contact').valid()) {
$('#ajax-contact').validate({
rules: {
name: {
rangelength: [2, 40],
},
email: {
rangelength: [2, 40],
email: true,
required: true
},
errorClass: "error",
highlight: function (input) {
$(input).closet('.required').removeClass('has-success').addClass('has-error');
}
}
})
} else {
$("#ajax-contact").css({'display:block'});
console.log('not working');
}
})
closestascloset.