How to Auto-Fill an Acrobat Date Field While Allowing Manual Edits
Question details
The user needs a method to automatically populate a PDF form's date field with the current date, while ensuring the field remains manually editable and does not overwrite user input during the session.

- Product
- Adobe Acrobat PDF
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where a date field defaults to today's date but allows the user to override it if necessary.
- Observed behavior
- A standard calculation script continuously overwrites manual input. The user requires a script that only inserts the date when the field is completely empty.
Ensure you have Adobe Acrobat Pro or a similar advanced PDF editor that supports adding document-level JavaScript. You will also need to know the exact field name of the date field you wish to target (e.g., 'MyField').
Add a Document-Level JavaScript
Use a document-level script that triggers when the PDF is opened, checking if the date field is empty before inserting the current date.
By placing the script at the document level rather than as a custom calculation on the field itself, the script runs once when the document is initialized. Adding a conditional check ensures it will not overwrite a date if the user has already manually typed one.
Open your PDF form in Adobe Acrobat. Go to the 'Tools' menu, select 'JavaScript', and then click on 'Document JavaScripts'.
Type a name for your script (e.g., 'AutoDate') in the Script Name field, and click 'Add'.
Delete any default code in the editor and paste the following: var f = this.getField("MyField"); if (f.value == "") f.value = util.printd("mm/dd/yyyy", new Date());
Replace 'MyField' in the script with the exact name of your form's date field. Click 'OK' to save and close the editor.
Save your PDF document, close it, and reopen it to verify that the empty date field automatically populates with today's date, and try editing it manually to ensure it accepts changes.

Easily Manage and Fill PDF Forms with WPS Office
WPS Office features a robust and comprehensive PDF editor that lets you view, fill, and manage interactive PDF forms effortlessly. Whether you are dealing with text fields, date inputs, or complex documents, WPS Office provides a streamlined experience.
- 1. Download and Install: Download WPS Office Free from the official website and install it on your device.
- 2. Open Your PDF Form: Launch WPS Office and open your interactive PDF form using the WPS PDF tool.
- 3. Fill the Fields: Click on any text or date field to instantly input your information. The interface highlights editable fields for easy navigation.
- 4. Save and Share: Once your form is filled, click 'Save' or export the document to share it securely with others.

Frequently Asked Questions
Why does my date field keep overwriting what I type manually?
If you placed the JavaScript in the field's 'Custom Calculation Script' section without a condition, it will continuously recalculate and overwrite your manual input. Moving the script to the Document-Level and using the `if (f.value == "")` condition ensures it only fills when the field is empty.
What happens to the date script if I flatten the PDF form?
Flattening a PDF form converts all interactive form fields into static text permanently. Once flattened, the JavaScript will no longer execute, and the date can no longer be edited.
Will this JavaScript work if the user opens the PDF in a web browser?
Many built-in web browser PDF viewers (like Chrome or Edge) have limited support for PDF JavaScript. For the auto-fill script to function correctly, the user should open the form in a dedicated PDF application like Adobe Acrobat or WPS Office.
Can I use this script for multiple date fields in the same document?
Yes. You can replicate the script for different fields by adding new variables and field names within the same Document-Level script, for example: `var f1 = this.getField("Date1"); if (f1.value == "") f1.value = util.printd("mm/dd/yyyy", new Date());` and repeat for 'Date2'.




