I am trying to validate my form and this is my code. It does work, but I need to click it twice for it to be correct. The first click is an error. Does anyone know why? Thanks in advance!
$.validator.addMethod('checkStartDate', function(value, element) {
  checkStartDate(value);
  return $('#validateDate').val();
});
function checkStartDate(value) {
  $.ajax({
    method: 'GET',
    url: '/API/AccountTimeTable/' + getIdFromAddressBar() + '?pgNo=1&pgSize=999'
  }).done(function(data) {
    console.log(data);
    $.ajax({
      method: 'GET',
      url: '/API/AccountRates/' + data[0].custAccountId
    }).done(function(data) {
      console.log(data);
      var startDataDate = new Date(parseDate(moment(data[0].effectiveStartDate).format('DD/MM/YYYY')));
      var startDate = new Date(parseDate(value));
      console.log(startDataDate);
      console.log(startDate);
      $('#validateDate').val(startDate >= startDataDate);
    });
  });
}
 
    