PDF Editing Issues

How to Multiply the Sum of Two PDF Form Fields by 2

Huma Ashraf ChHuma Ashraf Ch Nov 2, 2026 868 views

Question details

The user needs to calculate the sum of two specific PDF form fields and multiply that total by a fixed value (2) using a custom script, while avoiding formatting errors when inputs are blank.

How to Multiply the Sum of Two PDF Form Fields by 2
Product
PDF Editors
Device & OS
not provided
Scenario
Creating an interactive PDF form that requires automatic mathematical calculations based on user input.
Observed behavior
The user successfully implemented a calculation script but encountered 'NaN' (Not a Number) or formatting mismatch errors when the source fields were left blank prior to form completion.
Before you start

Ensure you know the exact names of the source form fields you intend to add together, as you will need to reference them identically in your calculation script.

Solution 1Recommended

Apply a Custom JavaScript for PDF Field Calculation

Use a custom calculation script within the result field's properties to add two source fields, multiply their sum by 2, and automatically output the result.

PDF form calculations rely on JavaScript to fetch values from other fields. By converting the field values to numbers, you can perform standard arithmetic operations reliably.

1
Access Result Field Properties

Enter form editing mode in your PDF editor. Right-click the result field where you want the final number to appear, and select 'Properties' from the context menu.

2
Enable Custom Scripting

In the Properties dialog box, navigate to the 'Calculate' tab. Choose the 'Custom calculation script' option and click the 'Edit' button.

3
Insert the Calculation Code

Paste the following script into the editor: var v1 = +getField("Text1").value; var v2 = +getField("Text2").value; event.value = 2 * (v1 + v2); Replace "Text1" and "Text2" with the actual names of your input fields.

4
Make the Field Read-Only

Navigate to the 'General' tab in the Properties window and check the 'Read-Only' box. This ensures that users cannot accidentally overwrite the automated calculation.

Apply a Custom JavaScript for PDF Field Calculation
Formatting the Result: You can go to the 'Format' tab and select 'Number' to restrict the result to a specific number of decimal places for a cleaner look.
Edit PDF Forms Easily

Manage Interactive PDF Forms with WPS PDF

WPS PDF offers a comprehensive suite of tools for viewing, filling, and editing interactive PDF forms. Whether you need to input data or manage document structures, WPS PDF provides a lightweight and highly compatible solution.

  1. 1. Open Your PDF Form: Launch WPS Office and open your interactive PDF document using the WPS PDF module.
  2. 2. Access Form Tools: Navigate to the 'Form' tab located on the top ribbon to view all available form fields and editing options.
  3. 3. Fill or Modify Fields: Click on any highlighted text field, checkbox, or dropdown menu to enter data, or use the editing tools to modify the document layout.
  4. 4. Save and Export: Once your form is complete, click 'Save' or 'Export to PDF' to secure your inputs in a universally compatible format.
Seamlessly fill and edit interactive PDF formsFully compatible with standard Adobe PDF document formatsLightweight architecture ensures fast loading and smooth navigationComprehensive annotation, editing, and conversion tools built-in
microsoft office alternative - wps office

Frequently Asked Questions

How do I find the exact name of a PDF form field?

In form editing mode, right-click the specific field and select 'Properties'. Under the 'General' tab, you will see the exact 'Name' of the field. This is the exact name you must use in the getField("FieldName") part of your script.

Why does my calculated field show 'NaN' or trigger an error message?

This usually happens when the script attempts to calculate a mathematical formula using empty fields or text strings instead of numbers. To fix it, ensure your script checks if the input fields are blank before performing the calculation.

Do I need to know advanced JavaScript to calculate PDF forms?

No, standard calculations like addition or multiplication only require basic JavaScript snippets. For simple sums or products, some PDF editors even offer built-in simplified field calculation options under the 'Calculate' tab without needing custom code.