PDF Editing Issues

How to Automatically Fill a PDF Field Based on Another Field's Data

Amos GikundaAmos Gikunda Oct 28, 2026 869 views

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.

How to Automatically Fill a PDF Field Based on Another Field's Data
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.
Before you start

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.

Solution 1Recommended

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.

1
Open form field properties

Enter Form Editing mode in your PDF editor, right-click on the destination field (Field B), and select 'Properties'.

2
Set field to read-only

In the General tab of the Properties dialog, check the box for 'Read-Only' so the automated value cannot be manually changed.

3
Add custom calculation script

Navigate to the Calculate tab, select 'Custom calculation script', and click the 'Edit' button.

4
Enter the JavaScript code

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).

5
Save and test

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.

Use a Custom Calculation Script to Conditionally Fill the Field
Check Field Names Carefully: JavaScript is case-sensitive. Ensure that the field name referenced in the script matches your source field's name exactly, including spaces and capitalization.
Advanced PDF Form Editing

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. 1. Open your PDF: Launch WPS Office and open your existing PDF document.
  2. 2. Access form tools: Navigate to the 'Form' tab on the top ribbon to view all form field options.
  3. 3. Edit field properties: Right-click the target text field, select 'Properties', and use the calculation tab to paste your JavaScript code.
  4. 4. Save and distribute: Save your newly interactive PDF document and share it with your users.
Create, edit, and fill interactive PDF forms with advanced conditional logic.Highly compatible with Microsoft Office formats and standard PDF form fields.Lightweight, user-friendly interface for seamless document management.
microsoft office alternative - wps office

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.