PDF Editing Issues

How to Auto-Populate a PDF Field from Two Different Date Fields

Camila MilosovichCamila Milosovich Nov 3, 2026 869 views

Question details

The user needs to set up a read-only PDF field that dynamically displays a date from a secondary field (Date2) if it has a value, or falls back to a primary field (Date1). If both are empty, the target field must remain blank.

How to Auto-Populate a PDF Field from Two Different Date Fields
Product
PDF
Device & OS
not provided
Scenario
Creating interactive PDF forms that require conditional logic to display dates automatically based on user input.
Observed behavior
The user requires a specific method or script to conditionally extract and populate data from two independent date fields into a third read-only field.
Before you start

Ensure that your PDF editing software supports JavaScript custom calculations and verify the exact, case-sensitive names of your date fields (e.g., 'Date1' and 'Date2') before applying the script.

Solution 1Recommended

Apply a Custom JavaScript Calculation

Use a simple JavaScript logical OR operator to check for a value in Date2 and fall back to Date1 automatically.

In PDF form fields, you can use custom calculation scripts written in JavaScript to handle conditional logic. By utilizing the logical OR operator (||), the script evaluates the first condition (Date2). If Date2 contains data, it displays it; if it is empty, it moves to the second condition and displays Date1.

1
Access Field Properties

Open your PDF document in form editing mode, right-click the read-only target field where you want the result to appear, and select 'Properties'.

2
Navigate to the Calculate Tab

In the Properties dialog box, click on the 'Calculate' tab to view the available calculation options for the field.

3
Enter the Custom Script

Select the 'Custom calculation script' option and click the 'Edit' button. Enter the following code exactly: event.value = this.getField("Date2").valueAsString || this.getField("Date1").valueAsString;

4
Save and Test

Click 'OK' to save the script, then close the Properties dialog. Exit form editing mode and test the functionality by entering dates into Date1 and Date2.

Apply a Custom JavaScript Calculation
Field Name Matching: The field names in the script must exactly match the names of your form fields. If your fields are named differently (e.g., 'StartDate' and 'EndDate'), update the script accordingly.
Advanced PDF Form Editing

Create and Manage Interactive PDF Forms with WPS Office

WPS Office provides comprehensive PDF editing tools, allowing you to easily create interactive forms, add text fields, configure field properties, and manage document logic.

  1. 1. Open PDF Edit: Launch WPS Office, open your PDF document, and click on the 'Form' tab in the top navigation ribbon.
  2. 2. Add Form Controls: Use the interactive form controls to insert 'Text Fields' for your dates and the target read-only field.
  3. 3. Configure Properties: Double-click the inserted target field to open the Properties dialog and set the field names.
  4. 4. Set to Read-Only: Under the 'General' tab in the Properties menu, check the 'Read Only' box for your target calculated field.
  5. 5. Save Document: Save your completed interactive PDF form to preserve the field logic and properties.
Easily insert, edit, and format PDF form fieldsFully compatible with standard PDF forms and Adobe Acrobat featuresLightweight application with a user-friendly interfaceSupports advanced PDF editing, signing, and conversion without complex setups
microsoft office alternative - wps office

Frequently Asked Questions

Can I use this script for standard text fields instead of date fields?

Yes, this JavaScript snippet uses the 'valueAsString' property, meaning it works perfectly for standard text fields, drop-downs, or any other field that outputs a string value.

Why is my target field showing an error or not updating?

This usually happens if the field names in your script do not exactly match the field names in your document. Check for typos, incorrect casing, or missing quotation marks in the script.

How do I make the target field read-only so users cannot type in it?

In the field properties dialog, navigate to the 'General' tab and check the 'Read Only' box. This ensures the field can only be populated by your calculation script, preventing manual overrides.