How to Automatically Fill a PDF Field Based on Another Field's Data
Question details
The user needs a fillable PDF form field (Field B) to automatically display specific text (e.g., 'dba') when another field (Field A) has a value, and remain blank when Field A is empty.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an advanced fillable PDF form with conditional logic between text fields.
- Observed behavior
- The goal state is for the secondary field to dynamically mirror a predefined text string based on the presence of input in the primary field, without manual user entry.
Ensure you are using a PDF editor that supports advanced form creation and JavaScript custom calculations, and verify the exact field name of your primary text box before writing the script.
Use a Custom Calculation Script to Conditionally Fill the Field
By setting the dependent field to read-only and applying a simple JavaScript ternary operator, the form will automatically populate the field based on the source field's status.
The script checks if 'Field A' contains any data. If it does, it outputs 'dba' into 'Field B'. If 'Field A' is empty, 'Field B' remains blank. Making the destination field read-only ensures users cannot accidentally overwrite the automated text.
Enter Form Editing mode in your PDF editor, right-click on the destination field (Field B), and select 'Properties'.
In the General tab of the Properties dialog, check the box for 'Read-Only' so the automated value cannot be manually changed.
Navigate to the Calculate tab, select 'Custom calculation script', and click the 'Edit' button.
Input the following script: event.value = getField("Field A").valueAsString ? "dba" : ""; (Be sure to replace 'Field A' with the exact name of your source field).
Click 'OK', close the properties dialog, and exit form editing mode. Type any text into Field A and click outside the box to see Field B update automatically.

Create and Manage Interactive PDF Forms with WPS Office
Easily design advanced interactive forms, manage form fields, and utilize JavaScript calculations directly within WPS Office's comprehensive PDF editor.
- 1. Open your PDF: Launch WPS Office and open your existing PDF document.
- 2. Access form tools: Navigate to the 'Form' tab on the top ribbon to view all form field options.
- 3. Edit field properties: Right-click the target text field, select 'Properties', and use the calculation tab to paste your JavaScript code.
- 4. Save and distribute: Save your newly interactive PDF document and share it with your users.

Frequently Asked Questions
Why isn't my PDF calculation script updating immediately?
PDF calculation scripts typically trigger when you exit the source field. You must click out of the source text box or press 'Tab' for the script to evaluate and update the target field.
Can I mirror the exact text from Field A into Field B instead of specific text?
Yes. To duplicate the exact text, change your custom calculation script to: event.value = getField("Field A").valueAsString;
Will custom calculation scripts work on mobile PDF viewers?
Support for JavaScript in PDFs varies heavily by mobile application. While desktop applications like WPS Office handle scripts perfectly, some basic mobile viewers may not execute automated field calculations.




