How to Automatically Fill Date When a PDF Name Field is Completed
Question details
The user wants a date field in a PDF sign-in form to automatically populate with the current date and time when the adjacent attendee name field is filled out.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Creating an interactive sign-in form that requires automatic timestamping for attendee entries to save time and ensure accurate record-keeping.
- Observed behavior
- The goal is to trigger an automatic date and time insertion into a specific date field whenever the corresponding name field is no longer empty.
Ensure you are using a PDF editor that supports JavaScript execution and advanced form field properties. You will need to know the exact field names for both your name input and date output fields before applying the script.
Use a Custom Validation Script to Auto-Fill the Date
By adding a short JavaScript snippet to the name field's validation settings, the date field will automatically update with the current date and time when a name is entered.
This method uses JavaScript to detect when the name field is filled and immediately outputs the system date and time into the adjacent date field. If the name is deleted, the script is designed to clear the date field as well.
Open your PDF form in edit mode. Right-click the name field (for example, the field named 'name1') and select 'Properties' from the context menu.
In the Properties dialog box, click on the 'Validate' tab to configure the field's validation behavior.
Select the 'Run custom validation script' radio button, then click the 'Edit' button. Paste the following code into the window: this.getField("date1").value = (event.value == "") ? "" : util.printd("mm/dd/yyyy HH:MM", new Date());
Click 'OK' to save the script and close the properties window. Switch to the form preview or viewing mode, type a name into the field, and press Enter to see the date field auto-populate.
Repeat this process for any other name/date field pairs on your sign-in sheet, making sure to update the target field name in the script (e.g., changing 'date1' to 'date2').

Create and Manage PDF Forms with WPS Office
WPS PDF provides a comprehensive set of tools for creating interactive forms, adding text fields, and managing advanced document properties efficiently without complex setup.
- 1. Open PDF Document: Launch WPS Office and open your existing PDF form or create a new blank document.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive form editing tools.
- 3. Insert Form Fields: Use the 'Text Field' option to insert input boxes for your names and dates on the document.
- 4. Configure Properties: Right-click any newly created field, select 'Properties,' and set up your formatting, validation scripts, or calculations.

Frequently Asked Questions
Can I change the date format in the custom validation script?
Yes, you can easily modify the "mm/dd/yyyy HH:MM" portion of the script. For example, use "dd/mm/yyyy" for a standard European format, or remove "HH:MM" if you only need the date without the specific time.
Why isn't the date field updating immediately after I type a name?
Validation scripts typically trigger when you exit or 'commit' the field. You need to press the Enter key, press Tab, or click outside the name field to trigger the script. Also, double-check that your target field name exactly matches the one written in the script.
Will this auto-fill script work on mobile PDF viewers?
Most basic mobile PDF readers and web browser viewers do not fully support JavaScript form calculations. For the auto-fill feature to function reliably, users should fill out the PDF using a robust desktop application like WPS Office or Adobe Acrobat.
How do I clear the date if the user accidentally types a name and then deletes it?
The provided script handles this automatically. The condition (event.value == "") ? "" acts as an IF statement, ensuring that if the name field becomes empty, the date field will also be cleared simultaneously.




