How to Conditionally Copy Text Between PDF Form Fields
Question details
The user wants to copy a value from one PDF form field (e.g., Height1) to others (Height2, Height3), but only if corresponding reference fields (UPC2, UPC3) are not blank.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating dynamic PDF forms with conditional logic for auto-filling fields.
- Observed behavior
- Destination fields need to dynamically update based on the presence of values in related reference fields, remaining blank when the reference fields are empty.
Determine if the destination fields should be read-only or if users need the ability to manually overwrite the automatically copied values. Ensure you have a PDF editor that supports adding custom JavaScript or calculation scripts to form fields.
Use Custom Calculation Scripts in PDF Form Fields
Apply a custom JavaScript calculation to the destination fields to check the status of related fields before copying data.
This method uses basic JavaScript to evaluate whether the reference field is empty. If it contains data, the script fetches the value from the source field and copies it to the destination field.
Open your PDF in form editing mode, right-click the destination field (e.g., Height2), and select 'Properties'.
Navigate to the 'Calculate' tab in the Properties window and select the 'Custom calculation script' option.
Click 'Edit' and enter the following script logic: if (this.getField('UPC2').valueAsString !== '') { event.value = this.getField('Height1').valueAsString; } else { event.value = ''; }
Repeat the process for the next destination field (e.g., Height3), updating the script to check the respective reference field ('UPC3'). Save your PDF to test the logic.

Create and Manage Dynamic PDF Forms with WPS Office
WPS Office provides robust PDF editing tools, making it easy to design interactive forms, manage form fields, and handle document workflows efficiently without relying on complex standalone software.
- 1. Open PDF in WPS: Launch WPS Office and open your PDF document containing the form fields.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all available form editing options.
- 3. Edit Field Properties: Double-click any text field to open its properties, where you can configure formatting, actions, and calculation rules.
- 4. Save the Form: Once your conditional logic is set up, click 'Save' to preserve the interactive form fields.

Frequently Asked Questions
Can I use basic calculations instead of custom scripts?
Basic calculations (like Sum or Product) are built into most PDF editors, but conditional logic (checking if another field is blank) requires a custom JavaScript calculation.
Why is the destination field not updating when I type?
Form fields typically update when you exit or 'commit' the current field. Press 'Enter' or click outside the reference field to trigger the calculation script.
How do I prevent users from changing the auto-filled text?
In the form field properties, go to the General tab and select the 'Read-Only' checkbox. This prevents manual editing of the field once the script has populated it.
Are JavaScript calculations supported in all PDF viewers?
Most standard desktop PDF viewers support JavaScript, but some mobile apps or browser-based viewers might strip out or ignore advanced form scripts. Always test your form in the intended viewer.




