Skip to main content
Participant
June 8, 2016
Answered

How do I create a text field that auto-populates a date three years from the current date?

  • June 8, 2016
  • 1 reply
  • 1109 views

I am trying to create a PDF form that will auto-populate an expiry date three years in the future from the current date in a created text field.

Text field name: ExpDate

Text field format: mm/dd/yy

So far I have entered the following into Page Properties --> Actions --> Add an Action (Trigger = Page Open, Action = Run a JavaScript):

var ExpDate = new Date();

ExpDate.setYear(ExpDate.getYear()+3);

var f=this.getField("ExpDate");

f.value=util.printd("mm/dd/yy", ExpDate);

This will produce the correct expiry date on the day that I make the certificate (i.e. it will read 06/07/16 on June 7, 2016), but when I open it the next day it will still ready 06/07/16 instead of 06/08/16. I am sure it is something simple that I need to change. Any ideas?

This topic has been closed for replies.
Correct answer try67

If it says "06/07/16" on June 7, 2016 that means it's not working correctly then, either, as it is not adding 3 years to the current date... It should show "06/07/19".

Are you seeing any error messages in the JS console (Ctrl+J) when you open the file?

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 8, 2016

If it says "06/07/16" on June 7, 2016 that means it's not working correctly then, either, as it is not adding 3 years to the current date... It should show "06/07/19".

Are you seeing any error messages in the JS console (Ctrl+J) when you open the file?

SRowneyAuthor
Participant
June 8, 2016

Hi try67,

Thanks for the quick reply! My apologies: "06/07/16" was a typo in my question. It should have read "06/07/19" in my question.

And, when I opened the file this morning... it worked!

For some reason, in my other attempts, I would look for the JS after the fact and it would be gone from the Action dialogue box. This time it stayed around. Woo-hoo!