PDF Editing Issues

Automatically Add or Clear a Date in an Acrobat Form

Amos GikundaAmos Gikunda Nov 25, 2026 868 views

Question details

The user needs an Acrobat form to add the current date when one text field contains a value and clear the date when that field is emptied.

Automatically Add or Clear a Date in an Acrobat Form
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF form has one text field for user input and a second field for the corresponding date.
Observed behavior
A Mouse Up script does not reliably update the date when the first field changes.
Before you start

Open the PDF in Acrobat and confirm that both text fields already exist. In Prepare a Form, check their exact field names so you can use the correct name for the date field in the script.

Solution 1Recommended

Add a Custom Validation Script to the Input Field

Use this method to update the date when the user commits an entry or clears the input field.

A validation event is more appropriate than Mouse Up because it responds to a committed field value rather than a mouse click. The script sets the date again whenever a nonempty value is validated.

1
Open the form editor

In Acrobat, open the PDF and select All tools > Prepare a form.

2
Open input field properties

Double-click text box 1, the field the user will fill in, and select the Validate tab.

3
Add the script

Select Run custom validation script, click Edit, and enter: this.getField("text box 2").value = event.value === "" ? "" : util.printd("dd mmmm yyyy", new Date()); Replace text box 2 with the exact name of your date field.

4
Save and test

Close the field properties, save the PDF, and test it in form-filling mode. Enter a value and leave the input field to commit it, then clear the field and leave it again to check that the date disappears.

Add a Custom Validation Script to the Input Field
JavaScript support: The PDF viewer must support and allow Acrobat form JavaScript. Test the saved form in the viewer your recipients will use.
Free Microsoft Office alternative

Work With PDFs and Office Files in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. It makes moving between common file formats easy, but it does not replace the Acrobat validation script needed for this form.

Open and work with PDF documents alongside other filesCompatible with Microsoft Office formats including DOCX, XLSX, and PPTXUse a familiar interface for a smoother transition from Microsoft OfficeWork with a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't a Mouse Up script reliably update the date?

Mouse Up responds to a mouse event, not every change to a field value. Add the script under the input field's Properties > Validate tab so it runs when the value is validated.

When will the date appear or disappear?

The date updates when the input field's value is committed, typically after you enter or clear the text and leave the field.

How do I change the date format?

In the custom validation script, change the format string in util.printd. For example, use "mm/dd/yyyy" instead of "dd mmmm yyyy".

Will the date stay the same if the input is edited later?

No. The script sets the current date each time a nonempty value is validated. It clears the date when the input is empty.

Why doesn't the script work in another PDF viewer?

The viewer may not support or allow Acrobat form JavaScript. Open the saved PDF in a viewer that supports it and check that JavaScript is enabled.