PDF Editing Issues

How to Automatically Copy a Field When Two PDF Form Values Match

Bushra ParveenBushra Parveen Nov 2, 2026 869 views

Question details

The user needs to automatically populate a text field with a specific value when two other numeric fields match within a PDF form.

How to Automatically Copy a Field When Two PDF Form Values Match
Product
PDF Form
Device & OS
not provided
Scenario
Creating dynamic PDF forms with conditional logic and custom calculation scripts to automate data entry.
Observed behavior
The custom calculation script fails to evaluate the condition correctly because it mistakenly uses an assignment operator (=) instead of an equality comparison operator (==).
Before you start

Ensure your PDF editor supports JavaScript for custom calculations in form fields, and double-check the exact field names (e.g., 'Numfield1') as JavaScript variables are case-sensitive.

Solution 1Recommended

Use the Equality Operator for the Conditional Check

Fix the syntax error by replacing the assignment operator (=) with the equality operator (==) to correctly compare the two field values in your script.

When writing custom calculation scripts for PDF forms, it is a common mistake to use a single equals sign for comparison. In JavaScript, a single equals sign assigns a value, which will cause your conditional check to fail or behave unpredictably. To compare values, you must use double equals (==) or check if the difference is zero.

1
Open Field Properties

Open your PDF document in editing mode, locate the target field where the copied value should appear (e.g., 'Namefield2'), right-click it, and select 'Properties'.

2
Navigate to the Calculate Tab

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

3
Edit the Custom Calculation Script

Select the 'Custom calculation script' radio button and click 'Edit'. Replace your existing conditional logic with the following script: var A = this.getField('Numfield1').value; var B = this.getField('Numfield2').value; if (A - B == 0) { event.value = this.getField('Namefield1').value; } else { event.value = ''; }

4
Apply and Test

Click 'OK' to save the script, then close the Properties dialog. Enter matching numeric values into 'Numfield1' and 'Numfield2' to test if 'Namefield2' populates correctly.

Use the Equality Operator for the Conditional Check
JavaScript Operators: In JavaScript, '=' assigns a value, while '==' compares values. Using 'A - B == 0' is a reliable way to compare numeric fields in PDF forms to avoid type-coercion issues.
Easily Edit PDF Forms

Create and Manage PDF Forms with WPS Office

WPS Office provides robust PDF editing capabilities, allowing you to create interactive forms, configure field properties, and manage dynamic PDF documents with ease.

  1. 1. Open WPS Office PDF: Launch WPS Office and open your PDF form document.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all interactive form controls.
  3. 3. Edit Field Properties: Double-click any form field to open its properties, where you can modify formats, actions, and custom calculations.
  4. 4. Save Document: Save your completed form as a standard PDF file that remains functional across all standard PDF readers.
Easily create, edit, and fill interactive PDF forms.Configure text fields, checkboxes, and calculation logic.Highly compatible with Microsoft Office formats and standard Adobe PDF files.Lightweight and user-friendly interface for seamless document workflow.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my PDF custom calculation script not working?

Script errors typically occur due to misspelled field names, missing semicolons, or using an assignment operator (=) instead of an equality operator (==) in an if-statement. Verify your syntax and ensure field names match exactly.

How do I clear a PDF form field if a condition is not met?

You can use an 'else' statement in your custom calculation script to set the 'event.value' to an empty string ("") when the condition evaluates to false, which automatically clears the field.

Are JavaScript field names in PDFs case-sensitive?

Yes, JavaScript is completely case-sensitive. Ensure that the field names referenced in your script (such as 'Namefield1' or 'Numfield1') match the actual capitalization of the fields created in the PDF form properties.

What is the difference between == and === in JavaScript form scripts?

The double equals (==) checks for value equality and performs type coercion if necessary (e.g., comparing a string '1' and a number 1). The triple equals (===) strictly checks for both value and data type equality.