How to Multiply Two Fields in Acrobat PDF Forms Using JavaScript
Question details
The user needs to set up a custom calculation script in an Acrobat PDF form that multiplies two fields and leaves the output field blank if either input is zero.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form that requires automated calculations based on user input.
- Observed behavior
- The user wants the calculation field to display the product of two specific fields but remain completely blank rather than displaying '0' when an input is missing or zero.
Ensure you have a PDF editor that supports advanced form creation and JavaScript editing, as standard PDF readers cannot edit form field properties or custom scripts.
Add a Custom JavaScript Calculation to the Output Field
Use a custom JavaScript in the Properties menu of your output field to calculate the product and set a conditional statement to keep it blank when inputs are zero.
Advanced PDF editors allow you to use JavaScript to perform complex calculations within form fields. By using an 'if-else' statement, you can control the output display perfectly, preventing zero values from cluttering your document when data has not yet been entered.
Enter the form editing mode in your PDF editor. Right-click on your output field (e.g., C1) and select 'Properties' from the context menu.
In the Properties dialog box, click on the 'Calculate' tab to access the calculation configuration options.
Choose the 'Custom calculation script' radio button and click the 'Edit' button to open the JavaScript editor window.
Type the following script exactly as shown, adjusting the field names if necessary: var a = this.getField('A1').value; var b = this.getField('B1').value; if (a == 0 || b == 0) event.value = ''; else event.value = a * b;
Click 'OK' to save the script, then close the Properties dialog. Exit form editing mode and test your form by entering numeric values into the input fields.

View and Fill Interactive PDF Forms with WPS Office
WPS Office includes a comprehensive PDF tool that allows you to easily view, fill, and manage interactive PDF forms. Whether you are working with embedded JavaScript calculations, digital signatures, or text fields, WPS PDF provides a smooth and accurate experience.
- 1. Open the PDF Form: Launch WPS Office and open your interactive PDF document from the file menu.
- 2. Fill the Input Fields: Click on the designated input fields and enter your data. The form's embedded JavaScript will execute automatically to display calculated results.
- 3. Save or Export: Once your form is filled and calculated, click 'Save' or export your PDF to share it securely with others.

Frequently Asked Questions
Why is my PDF calculation field showing a syntax error?
Syntax errors usually occur due to missing semicolons, incorrect quotation marks, or mismatched field names. Check your script to ensure 'A1' and 'B1' exactly match your form field names and that all punctuation matches the required JavaScript format.
Can I multiply more than two fields using this custom script method?
Yes. You can declare additional variables (for example, var c = this.getField('C1').value;) and modify your formula to 'event.value = a * b * c;'. Update the conditional statement to 'if (a == 0 || b == 0 || c == 0)' to keep it blank if any input is missing.
How do I hide the zero value using Simplified Field Notation?
Simplified field notation does not support complex conditional logic like hiding zero values directly. To leave a field blank when the mathematical result is zero, you must use a Custom Calculation Script with an 'if/else' statement.
Why isn't my PDF calculation output updating automatically?
Sometimes the calculation order in complex forms gets scrambled, meaning the output calculates before the inputs are registered. You can fix this by going to Form Edit mode, finding the calculation order settings, and ensuring your input fields process before the final output field.




