How to Set a Default Form Value Only When Another Field Is Filled in PDF
Question details
The user wants to automatically populate a secondary form field (like a description) when a primary field (like a date) is filled, and keep it blank when the primary field is empty.

- Product
- WPS PDF
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms where conditional logic is needed to streamline user data entry.
- Observed behavior
- The user requires a method to dynamically update a secondary field's value based on whether the primary trigger field contains data.
Ensure that your PDF editor supports JavaScript for form validation, and note down the exact case-sensitive names of the fields you want to link.
Use a Custom JavaScript Validation Script
Add a validation script to the primary trigger field so it automatically sets the value of the secondary field based on its own input status.
PDF forms support JavaScript to handle dynamic logic. By adding a simple validation script to your primary field, you can control the text that appears in a target field automatically.
Enter the form editing mode in your PDF application. Right-click the primary field (e.g., the Date field) that will trigger the change and select 'Properties'.
Navigate to the 'Validate' or 'Validation' tab in the Properties window, and select the option to run a custom JavaScript.
Enter the following code: if (event.value == "") this.getField("Description").value = ""; else this.getField("Description").value = "Description goes here";
Replace 'Description' in the script with the exact name of your secondary target field, and change 'Description goes here' to the default text you want to populate.
Close the properties dialog, exit form editing mode, and test the form by entering a value into the primary field to see the secondary field populate.

Create and Edit Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor to help you design interactive forms, manage field properties, and ensure seamless document data collection.
- 1. Open your PDF: Launch WPS Office and open the PDF document you want to edit.
- 2. Navigate to the Form Tab: Click on the 'Form' tab on the top ribbon to access the interactive form tools.
- 3. Insert and Edit Fields: Click to add new form fields or double-click existing ones to modify their properties and logic.

Frequently Asked Questions
Why isn't my target PDF form field updating automatically?
Make sure you entered the exact field name in the JavaScript code, as field names are case-sensitive. Additionally, ensure your PDF viewer has JavaScript execution enabled.
Can I use this method to link a checkbox to a text field?
Yes, you can modify the JavaScript to check the state of a checkbox (e.g., checking if event.value is 'Yes' or 'Off') instead of checking if a text field is empty.
Will the auto-filled value overwrite the user's manual input?
The validation script triggers only when the primary field is modified. If a user manually edits the secondary auto-filled field afterwards, their changes will remain unless the primary field is altered again.




