Validation plugin auto clear error message after chaning value text box

Validation plugin auto clear error message after chaning value text box

Hi everyone,

I use validattion plugin to validate 2 textbox (date of birth - DOB, issued date - ISSDT) using datepicker plugin. DOB textbox is checked over 18 years old (It means now - DOB >= 18). Another one is checked for greatering than DOB: 14 years old (It means ISSDT - DOB >= 14). I selected wrong value for all textbox to display error  message 1, error message 2. When i changed from wrong value in DOB to right value and it's valid for ISSDT, but it's only to clear message 1. How do i do to clear all error message when every textbox are right? 

Help me, please. Thanks in advance :)

  1. $("#mainForm").validate({
  2.                 messages:
  3.                 {
  4.                     txtDOB:
  5.                     {
  6.                         checkDateOfBirth: "Chủ tài khoản chưa đủ 18 tuổi. Hãy nhập lại!",
  7.                     },
  8. txtIdIssueDate:
  9. {
  10. checkIdentityCard: "Kiểm tra lại ngày cấp CMT và ngày sinh!"
  11. }
  12.                 },
  13.                 invalidHandler: function(event, validator) {
  14.                     event.preventDefault();
  15.                     event.stopPropagation();
  16.                 }
  17.             });
  18.             $.validator.addMethod("checkDateOfBirth", function(value, element){
  19.                       var inputDate = $('#txtDOB').val();
  20.                       var currdate = new Date();
  21.                       var yearInput = 18;
  22.                       return compareDate(inputDate, currdate, yearInput, '>=');
  23.             });
  24.             $.validator.addMethod("checkIdentityCard", function(value, element){
  25.  var frDate = $("#txtDOB").val();
  26.  var toDate = $("#txtIdIssueDate").val();
  27.  var yearInput = 14;
  28.                           return compareDateStr(frDate, toDate, yearInput, '>=');
  29.             });
  30.             var test = {
  31.                 txtCheckDateOfBirth: {
  32.                     checkDateOfBirth: true
  33.                 },
  34. txtIdIssueDate: {
  35. checkIdentityCard: true
  36. }
  37.             }
  38.             $("#txtDOB").rules('add', test['txtCheckDateOfBirth']);
  39. $("#txtIdIssueDate").rules('add', test['txtIdIssueDate']);
  40. $(".datepicker").datepicker('option', {
  41.                 onClose: function(dateText, inst){
  42. $(this).valid();
  43.                 }
  44.             });