How to Auto-Calculate PDF Form Fields While Allowing Manual Overwrite
Question details
The user needs to create a calculated PDF form field that updates automatically based on other field inputs, but still allows users to manually edit and retain a custom value without the script resetting it.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Designing an interactive PDF form with dynamic calculated fields where manual adjustments to the final calculated value are sometimes required.
- Observed behavior
- Standard PDF calculation scripts run continuously on any form change, which immediately erases and resets any manually overwritten data in the target field.
Ensure you are using a professional PDF editor that supports adding custom JavaScript to form fields, as basic calculation features cannot support conditional overwrites.
Use a Custom JavaScript Calculation with event.source
Applying a conditional JavaScript ensures the calculation only triggers when specific source fields are modified, leaving manual overrides intact during other form interactions.
By default, PDF scripts recalculate whenever any field in the document changes. By explicitly checking the `event.source` object in your script, you can restrict the calculation to run only when the specific dependent fields are updated.
Open your PDF form editor and ensure every input field and the target calculated field has a completely unique name to avoid scripting conflicts.
Right-click the target field (where you want the calculated or overwritten value to appear) and select 'Properties' from the context menu.
In the Properties dialog, switch to the 'Calculate' tab and select the option for 'Custom calculation script', then click the 'Edit' button.
Write a script that checks the source of the event. For example: `if (event.source && event.source.name == 'InputName') { event.value = this.getField('InputName').value * 2; }`. Replace 'InputName' and the calculation logic with your specific field names and formula.
Click 'OK' to save the script and close the properties window. Test the form by modifying the source field to trigger the calculation, then manually type a new value into the target field. Edit an unrelated field to confirm your overwritten value does not reset.

Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive suite of PDF tools, allowing you to easily add, edit, and manage interactive form fields, including setting up custom calculations and JavaScript formatting.
- 1. Open PDF in WPS Office: Launch WPS Office and open your PDF document.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all interactive form controls.
- 3. Add Interactive Fields: Select 'Text Field' or other form controls and click on your document to place them.
- 4. Configure Field Properties: Double-click the inserted field to open properties, where you can navigate to the Calculate tab to add custom JavaScript.

Frequently Asked Questions
Why does my manually entered value disappear in a calculated PDF field?
By default, PDF form calculation scripts execute every time any field in the document changes. This forces the calculated field to refresh based on the formula, wiping out your manual entry. Using a conditional script prevents this default behavior.
Can I use basic mathematical operators instead of JavaScript to achieve this?
No. The built-in basic calculation options (like Sum or Product) apply standard calculation rules that cannot be bypassed conditionally. You must use a custom JavaScript calculation to allow manual overwriting without immediate resets.
What happens if a user clears the form?
If a user selects a 'Reset Form' button, both the source inputs and the manually overwritten fields will be cleared. The script will wait until new data is entered into the specific source field before calculating again.




