How to Retain Dialog Values and Calculate Running Totals in Acrobat PDF
Question details
The user needs to keep custom JavaScript dialog values intact upon reopening the dialog and properly calculate a mathematical sum of inputs instead of concatenating them as strings.

- Product
- Adobe Acrobat Pro DC
- Device & OS
- not provided
- Scenario
- Using a custom JavaScript dialog in a PDF form to collect and add monthly overtime amounts.
- Observed behavior
- Previously entered values disappear when the dialog is reopened, and calculating the totals concatenates the numbers (e.g., producing 500650300 instead of the correct sum of 1450) because the inputs are treated as strings.
Ensure you have access to the JavaScript editor in Acrobat Pro DC and that you have created hidden or visible document-level form fields in your PDF to store the monthly data temporarily.
Store Dialog Data in Form Fields and Parse Inputs as Numbers
Use hidden or regular PDF form fields to save dialog data upon closing, and convert string inputs to numerical values using the Number() constructor to perform correct mathematical addition.
Acrobat JavaScript dialogs reset to a completely blank state every time they are invoked. For a value to appear in the dialog window, you must explicitly populate it during initialization.
Additionally, data pulled from form fields or dialog inputs are typically treated as text strings. If you use the plus (+) operator on strings, JavaScript concatenates them. You must convert these strings to numeric values before calculating a running total.
Before opening the dialog, instruct your JavaScript object to pull existing data from the PDF form fields. For example: RepInfoDlg.month1 = Number(this.getField('Month1').value); This populates the dialog with previously entered information.
When reading the user's input from the dialog, wrap the values in the Number() constructor (e.g., Number(rslt['mon1'])) so JavaScript correctly interprets the data as numerical integers or floats.
Add the converted numeric variables together and assign the result to your total field. For example: this.getField('OTBill1').value = Number(RepInfoDlg.month1) + Number(RepInfoDlg.month2);
Once the user selects 'OK' on the dialog, ensure your script writes the individual dialog values back to their corresponding hidden or regular document fields. This safely stores the data so it remains available the next time the dialog opens.

Manage PDF Form Fields Easily with WPS Office
If debugging complex JavaScript dialogs becomes too time-consuming, WPS Office offers an intuitive alternative. WPS Office provides built-in tools to create, fill, and manage interactive PDF form fields seamlessly, removing the need for advanced scripting knowledge.
- 1. Open your PDF form in WPS Office: Launch WPS Office and open the PDF document that contains your interactive form fields.
- 2. Access the Form editing tools: Navigate to the 'Form' tab on the top ribbon. Here you can easily view, highlight, and manage all fillable fields in the document.
- 3. Input and save values securely: Type your data directly into the fields. WPS Office natively retains all inputted numerical values and form data securely when you save the document, without requiring background JavaScript retention scripts.

Frequently Asked Questions
Why are my PDF form fields concatenating numbers instead of adding them?
By default, JavaScript reads form field inputs as text strings. When you use the addition operator (+) on strings, it stitches the text together (concatenation). You must wrap the variables in the Number() function to convert them to integers or decimals before adding them.
How do I retain input data in an Acrobat JavaScript dialog?
Acrobat JavaScript dialogs do not save state; they reset to blank every time they are opened. To retain data, you must store the user inputs in hidden or visible PDF document fields when the dialog is closed, and configure the script to load those field values back into the dialog during its initialization phase.
Can I use hidden fields to store data in a PDF?
Yes, you can create standard text fields in a PDF and set their visibility property to 'Hidden'. This allows them to act as invisible background storage for custom JavaScript variables without affecting the visual layout of your document.




