Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Jun 07, 2016 Jun 07, 2016

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?

TOPICS
Acrobat SDK and JavaScript , Windows
989
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 08, 2016 Jun 08, 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?

Translate
Community Expert ,
Jun 08, 2016 Jun 08, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 08, 2016 Jun 08, 2016
LATEST

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines