Update a date input based on first date input + 1year
I have two dates I need to collect in a form.
<input type="text" name="EffectiveDate" id="EffectiveDate" />
<input type="text" name="ExpirationDate" id="ExpirationDate" />
Effective Date is entered as mm/dd/yyyy
Expiration Date needs to be formatted as mm/dd/yyyy
I need ExpirationDate to auto enter to be 1 year more than the Effective Date.
I tried the following.
$(document).ready(function() {
$("#EffectiveDate").change(function () {
var d = new Date();
d.setDate(d.getDate());
$("#ExpirationDate").val(formatDate(_date));
});
function formatDate(date) {
var day = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear() + 1;
if (day < 10) day = "0" + day;
if (month < 10) month = "0" + month;
return day + "/" + month + "/" + year;
}
Any suggestions appreciated.
Thanks,
Joe Scarpetta
Apphia Solutions, LLC