Search code examples
javascriptformsacrobat

Setting a future date based on a field value in Javascript


I have an Acrobat form that accepts a date for a notice to a customer. The customer has 20 days to respond, and I need the notice to calculate a field that auto-populates the correct day 20 day later.

I have the following code:

if (getField("chkCounterOffer").value != "On") {
     event.value = "";
}
else {
    var d = new Date(getField("fldNoticeDate").value);
    event.value = util.printd("mm/dd/yyyy", new Date(d.getMonth(),(d.getDate() + 20),d.getFullYear()));
    calculateNow();
}

but it's throwing an error. The current date (fldNoticeDate.value) 02 Jul 2019 produces a future date of 07 November 1912.

What am I formatting wrong?


Solution

  • Your year needs to come first in your parameters.

    event.value = util.printd("mm/dd/yyyy", new Date(d.getFullYear(), d.getMonth(),(d.getDate() + 20)));
    

    https://www.w3schools.com/js/js_dates.asp