How to Automatically Copy a Field When Two PDF Form Values Match
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.

- 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 (==).
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.
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.
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'.
In the Properties dialog box, click on the 'Calculate' tab to view the calculation options for the selected field.
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 = ''; }
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.

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. Open WPS Office PDF: Launch WPS Office and open your PDF form document.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all interactive form controls.
- 3. Edit Field Properties: Double-click any form field to open its properties, where you can modify formats, actions, and custom calculations.
- 4. Save Document: Save your completed form as a standard PDF file that remains functional across all standard PDF readers.

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.




