-1

I am trying to set jQuery to allow me to populate a secondary field on a form based on the date that is selected on a calendar.

If date selected in a Date field is earlier or equal to 90 days populate another field

I have tried to have a look through some of the articles on the site but cant find anything that matches this requirement there are some calendar or data picker queries but nothing with a less than or equal to which populates an additional field.

Any help would be great, Thanks

Ballyb
  • 11
  • 1

1 Answers1

0

Is this what you are trying to achieve?

$('#myDate').change(checkdate)

function checkdate() {
  let date90daysAgo = new Date();
  date90daysAgo.setDate(date90daysAgo.getDate() - 90);
  var selectedDate = $('#myDate').val().split(/\D/);
  selectedDate = new Date(selectedDate[0], --selectedDate[1], selectedDate[2]);
  if(date90daysAgo >= selectedDate) {
    $('#answer').text("yes");
  } else {
    $('#answer').text("no");
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="myDate" type="date"></input>
<p>Is the date more than 90 days ago?<p>
<p id="answer"></p>
Timothy Alexis Vass
  • 2,526
  • 2
  • 11
  • 30