How to Use IF/ELSE Calculations in PDF Form Fields
Question details
The user wants to create a PDF form field that calculates a value based on an item count but allows manual entry if the count is zero or empty.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form with conditional calculation logic for pricing or weight.
- Observed behavior
- The user needs to implement conditional logic where a field outputs a calculated value under certain conditions but functions as a manual input otherwise.
Ensure you have a PDF editor that supports form field editing and JavaScript calculations, and identify the exact names of the fields you want to reference in your formula.
Add a Custom JavaScript IF/ELSE Script
Use a custom JavaScript calculation script in the target form field to evaluate conditions before displaying a value.
A single PDF form field generally cannot be both fully calculated and manually editable at the same time without conflicting behaviors. The best approach is to use a calculation script that outputs a value when conditions are met, or leaves it blank to avoid errors.
Open your PDF form in edit mode and right-click the target field (e.g., the Total Price or Weight field) to open its 'Properties'.
Navigate to the 'Calculate' tab within the Field Properties dialog box.
Select the option for 'Custom calculation script' and click the 'Edit' button.
Enter your IF/ELSE script. For example: var pieces = Number(this.getField("Pieces").value); var weight = Number(this.getField("Piece Weight").value); var price = Number(this.getField("Price per Kilogram").value); if (pieces >= 1) { event.value = pieces * weight * price; } else { event.value = ""; }
Click 'OK' to save the script, close the properties window, and test your form by entering values in the referenced fields.

Use Separate Fields with a Toggle Checkbox
Prevent calculation conflicts by separating the calculated result from the manual entry input using a toggle.
Create and Edit PDF Forms with WPS Office
WPS PDF offers a comprehensive suite of tools for creating interactive PDF forms, adding text fields, and managing document workflows efficiently without the heavy cost of Adobe Acrobat.
- 1. Open WPS Office: Launch WPS Office and switch to the 'PDF' tab from the main interface.
- 2. Load Your Document: Open your existing PDF document or create a new blank PDF.
- 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive form controls.
- 4. Insert Fields: Click to add Text Fields, Checkboxes, and other interactive elements to your document.
- 5. Adjust Properties: Double-click the inserted fields to adjust their properties, appearance, and calculation settings.

Frequently Asked Questions
Why can't I manually type into a calculated PDF field?
When a field is set to calculate automatically, the PDF viewer constantly overwrites any manual input with the result of the calculation script. To allow manual entry, you must either disable the calculation or use a separate field.
How do I reference another field in a PDF JavaScript calculation?
You can retrieve the value of another field using the syntax this.getField("FieldName").value. Make sure to wrap it in Number() if you need to perform mathematical operations on the retrieved value.
Does WPS PDF support JavaScript calculations in forms?
WPS PDF supports standard interactive form fields and basic calculations. For advanced custom JavaScript calculations, compatibility may vary depending on the specific scripts used compared to Adobe Acrobat.
What happens if the referenced field is empty?
In JavaScript, an empty field value is often treated as zero when converted to a number. Using an IF/ELSE statement allows you to check if the value is greater than zero before performing the calculation, preventing unwanted zero results.




