How to Add or Subtract Values in a PDF Form Field
Question details
The user wants a PDF form field to start at zero and automatically add or subtract values when a user enters a number with a leading plus or minus sign.

- Product
- Adobe Acrobat Pro
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms where specific fields need to dynamically accumulate totals based on incremental adjustments entered by the user.
- Observed behavior
- By default, entering a value like +10 or -5 simply replaces the current value with the new text rather than mathematically adjusting the existing number.
Ensure your PDF editor supports JavaScript for form fields, and create a backup copy of your document before applying custom scripts to prevent data loss.
Apply a Custom Validation Script to the Form Field
Use a custom JavaScript snippet in the field's properties to detect plus or minus signs and evaluate them against the current value.
This solution utilizes JavaScript to intercept the user's input. If the script detects a leading '+' or '-', it evaluates the mathematical expression and updates the field with the newly calculated total.
Open your PDF form in Edit mode, right-click the target form field, and select Properties from the context menu.
Navigate to the Options tab and set the Default Value to 0. This ensures the script has a valid baseline number to calculate against.
Go to the Validate tab, select 'Run custom validation script', and click the Edit button.
Paste the following code exactly as shown: if (event.value && /^[\\+-]/.test(event.value)) event.value = eval(event.target.value + '' + event.value);
Save the changes, exit Edit mode, and type +10 or -5 into the field to verify that the value adjusts correctly based on the previous total.
Create and Manage Interactive PDF Forms with WPS Office
WPS PDF provides comprehensive tools for creating, filling, and managing interactive PDF forms. Whether you need to insert text fields, checkboxes, or interactive elements, WPS makes form handling straightforward and efficient.
- 1. Open WPS PDF: Launch WPS Office and open your PDF document using the built-in WPS PDF tool.
- 2. Access the Form Tab: Navigate to the Form tab on the top ribbon to access the suite of interactive field tools.
- 3. Edit or Fill Fields: Click on existing fields to fill them out, or use the form creation tools to insert new interactive text fields and checkboxes.
- 4. Save and Export: Once your form is properly configured or filled, click Save to preserve the interactive elements for future data entry.

Frequently Asked Questions
Why is my PDF form JavaScript not executing?
JavaScript execution might be disabled in your PDF viewer's security settings. Ensure that 'Enable Acrobat JavaScript' (or your software's equivalent setting) is checked in the Preferences menu.
Can I use this calculation script in standard web browsers?
Most built-in browser PDF viewers do not fully support custom JavaScript actions or advanced form validation scripts. It is highly recommended to use dedicated PDF software to fill out forms requiring complex calculations.
How do I set the starting value of my form field to zero?
Right-click the form field, select Properties, go to the Options tab, and type '0' in the Default Value field. This step guarantees the calculation script has a valid numeric baseline to perform addition and subtraction.




