PDF Editing Issues

Populate and Clear an Acrobat Date Field Based on Text Input

Rana GarciaRana Garcia Nov 19, 2026 868 views

Question details

Populate DateField1 with the current date when Name1 contains text and clear the date when Name1 is empty.

Populate and Clear an Acrobat Date Field Based on Text Input
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.
Before you start

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.

Solution 1Recommended

Add a validation script to the Name1 field in Acrobat

Use this script to update DateField1 whenever a change to Name1 is committed.

1
Open the form editor

Open the PDF in Acrobat and select All tools > Prepare a form.

2
Open the name field properties

Double-click the Name1 field, then select the Validate tab in its Properties dialog.

3
Add the script

Select Run custom validation script, click Edit, and enter: this.getField("DateField1").value = event.value == "" ? "" : new Date();

4
Set the date format

Open DateField1 Properties, select the Format tab, choose Date, and select the display format you want.

5
Save and test the form

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.

Add a validation script to the Name1 field in Acrobat
When the date changes: The script sets the current date whenever a nonempty change to Name1 is committed, so editing the name later can update the date. It checks for an empty string; spaces alone are not treated as empty.
Free Microsoft Office alternative

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.

Open and work with PDF documents alongside Office filesCompatible with Microsoft Word, Excel, and PowerPoint formatsUse a familiar interface for a smoother transitionKeep common document tools in one lightweight suite
microsoft office alternative - wps office

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.