i am using a jquery validation in form my code is following
Jquery
$(document).ready(function () {
$('#myformid').validate();
$.validator.addMethod("endDate", function (value, element) {
var startDate = $('.startDate').val();
return Date.parse(startDate) <= Date.parse(value);
}, "* End date must be Equal/After start date");
});
i am trying to compare two dates with jquery , if the end date is greater then start date then jquery shows validation error ,but after showing error if i input some valid date the validation message doesn’t disappear until i submit my form . What should be be the problem ?
If you change only the endDate, the validation should work correctly (see here, submit the form, then fix the endDate, and the error message will disappear), but I’m guessing your problem is when you change the startDate to correct the problem with the endDate…
In that case, you need to trigger the
endDatevalidation when startDate changes also:The if statement just checks whether the endDate input is already in the “error” state and then re-validates it if it is.
validateObjectis the validate object, which is returned from$('#myformid').validate().You can see that version in action here: http://jsfiddle.net/ryleyb/zhN6q/1/