Populate and Clear an Acrobat Date Field Based on Text Input
Question details
Populate DateField1 with the current date when Name1 contains text and clear the date when Name1 is empty.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form has a name field and a date field that should change based on the name field's value.
- Observed behavior
- The date field should show the current date after a name is entered and become blank after the name is cleared.
Open the PDF in Adobe Acrobat and check that its form fields are named Name1 and DateField1. Make sure JavaScript is enabled in Acrobat preferences.
Add a validation script to the Name1 field in Acrobat
Use this script to update DateField1 whenever a change to Name1 is committed.
Open the PDF in Acrobat and select All tools > Prepare a form.
Double-click the Name1 field, then select the Validate tab in its Properties dialog.
Select Run custom validation script, click Edit, and enter: this.getField("DateField1").value = event.value == "" ? "" : new Date();
Open DateField1 Properties, select the Format tab, choose Date, and select the display format you want.
Save the PDF, exit form editing, and enter a name in Name1. Commit the entry by leaving the field, then clear it and leave the field again to check that DateField1 also clears.

Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight alternative for everyday document and PDF work. Its familiar interface and Microsoft Office format support make it easy to bring existing files into your workflow. The Acrobat-specific form script above must be configured and tested in Acrobat.

Frequently Asked Questions
Where do I put the JavaScript in Acrobat?
In Prepare a form, open Name1 Properties, select Validate, and add the code under Run custom validation script.
Why doesn't the date change while I am typing?
The validation script runs when the Name1 value is committed, typically when you leave the field. Enter or clear the name, then click another field to test it.
How do I change the displayed date format?
In Prepare a form, open DateField1 Properties and use the Format tab to select Date and a preferred date format.
Will the original date stay the same if I edit the name later?
No. This script assigns the current date whenever a nonempty change to Name1 is committed. Clearing Name1 also clears DateField1.




