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

Javascript insert date to field for first time only

Contributor ,
Feb 14, 2020 Feb 14, 2020

Copy link to clipboard

Copied

Hi all, 

 

I have a form that I want the date field to be automatically populated. 

I found a javascript online that inserts the date when i open the file. (https://codeshare.io/5g1lOB)

 

If i reopen the filled out form the next day, the date is updated.

Is there a way for the javascript to insert the date and then delete itself? 

TOPICS
How to , PDF forms

Views

2.6K

Translate

Translate

Report

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

LEGEND , Feb 15, 2020 Feb 15, 2020

PDF form fields have a "default value" property and if properly set can be used to only fill in the date field when the form is opened.  I would also set the format of the field to "None" and let the script apply the formatting for the date.

 

I would use the following document level script:

 

 f = this.getField ("DATE");
 if (f.value == f.defaultValue)
 {
f.value = util.printd ("yyyy-mm-dd", new Date ());

This approach also allows the form to be tested and then easily set for uploading or distrib
...

Votes

Translate

Translate
Community Expert ,
Feb 14, 2020 Feb 14, 2020

Copy link to clipboard

Copied

Set the value of the field only when the field is empty.

Votes

Translate

Translate

Report

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 Expert ,
Feb 15, 2020 Feb 15, 2020

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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
LEGEND ,
Feb 15, 2020 Feb 15, 2020

Copy link to clipboard

Copied

LATEST

PDF form fields have a "default value" property and if properly set can be used to only fill in the date field when the form is opened.  I would also set the format of the field to "None" and let the script apply the formatting for the date.

 

I would use the following document level script:

 

 f = this.getField ("DATE");
 if (f.value == f.defaultValue)
 {
f.value = util.printd ("yyyy-mm-dd", new Date ());

This approach also allows the form to be tested and then easily set for uploading or distribution by simply resetting the form.

}


 

Votes

Translate

Translate

Report

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