PDF Editing Issues

Populate a PDF Date Field Only Once Using JavaScript

Jason MillerJason Miller Nov 2, 2026 869 views

Question details

The user needs to insert the current date automatically into an Acrobat PDF form field the first time it is opened, ensuring the date does not update again when the completed PDF is reopened.

How to Populate a PDF Date Field Only Once with JavaScript
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating an interactive PDF form that requires a static, one-time date stamp upon initial opening.
Observed behavior
Standard date scripts typically overwrite the date field with the current date every time the PDF is opened, losing the original completion date.
Before you start

Ensure you have access to a PDF editor that supports document-level JavaScript, such as Adobe Acrobat Pro, and keep a backup copy of your original form before applying new scripts.

Solution 1Recommended

Add a Document-Level JavaScript to Check the Default Value

Use a conditional JavaScript that checks if the date field is empty or at its default value before inserting today's date, preventing it from overwriting existing data.

By using the 'defaultValue' property, the script can distinguish between a brand new form and one that has already been filled and saved. If the field retains its default value, the script populates the current date; if it holds a previously saved date, the script ignores it.

1
Format the Date Field

Open your PDF form in Adobe Acrobat. Right-click your date field (e.g., named 'DATE'), select 'Properties', and navigate to the 'Format' tab. Set the format category to 'None' so the script has full control over the date string formatting.

2
Open Document JavaScripts

Go to the 'Tools' menu, select 'JavaScript', and then click on 'Document JavaScripts'. Type a name for your script (like 'AutoDate') and click 'Add'.

3
Insert the Conditional Script

Delete any default code in the editor and paste the following: var f = this.getField("DATE"); if (f.value == f.defaultValue) { f.value = util.printd("yyyy-mm-dd", new Date()); }

4
Save and Test

Click 'OK' and close the JavaScript editor. Save your PDF document, close it, and reopen it. The date should populate immediately. Save the file again, close it, and reopen it the next day to verify the date remains unchanged.

Add a Document-Level JavaScript to Check the Default Value
Field Name Match: Ensure the field name in the script exactly matches the form field name in your PDF. JavaScript is case-sensitive, so 'DATE' and 'Date' are considered different fields.

Fill and Manage PDF Forms Easily with WPS Office

While creating complex JavaScript routines requires advanced PDF builders, you can easily open, fill, edit, and sign interactive PDF forms using WPS PDF. It provides a lightweight, fast, and user-friendly experience for everyday PDF tasks.

  1. 1. Download and Install: Download WPS Office from the official website and install it on your computer or mobile device.
  2. 2. Open Your PDF Form: Launch WPS PDF and open the interactive PDF form you need to fill out.
  3. 3. Fill and Sign: Click directly into the form fields to input your data or dates, and use the 'Sign' tool to add your electronic signature.
  4. 4. Save the Document: Click 'Save' or press Ctrl+S. WPS PDF will lock in your entries accurately, preserving your data for the next time it is opened.
Seamlessly open and interact with standard fillable PDF forms.Highly compatible with Microsoft Office formats and standard PDF files.Lightweight architecture ensures fast loading of heavy PDF documents.Built-in electronic signature and annotation tools.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my PDF date change every time I open the document?

This happens when a basic dynamic date script is applied without a condition. A standard script runs every time the document initializes, replacing whatever text is in the field with the current system date. Adding a condition to check for a default value fixes this.

Can I use this JavaScript for other form fields?

Yes. The logic of checking if a field equals its default value before applying a change can be used for any text field, dropdown, or checkbox where you only want an action to occur upon the very first opening of the form.

Does the recipient need special software to see the date?

The recipient needs a standard PDF reader that supports JavaScript execution (like Adobe Acrobat Reader or WPS PDF) to ensure the script triggers when they first open the blank form. Once saved, the date becomes static text.

What if my date format needs to be different?

You can change the format by adjusting the 'yyyy-mm-dd' portion of the script. For example, use 'mm/dd/yyyy' for a standard US date format, ensuring the field formatting is still set to 'None'.