PDF Editing Issues

How to Retain Dialog Values and Calculate Running Totals in Acrobat PDF

Muhammad TalhaMuhammad Talha Nov 3, 2026 869 views

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.

How to Retain Dialog Values and Calculate Running Totals in Acrobat PDF
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.
Before you start

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.

Solution 1Recommended

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.

1
Load existing values into the dialog

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.

2
Convert string inputs to numeric values

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.

3
Calculate the mathematical total

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);

4
Write the values back to the form fields

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.

Store Dialog Data in Form Fields and Parse Inputs as Numbers
Using Hidden Fields: You do not need to clutter your PDF with visible text fields to store background variables. You can set the form fields to 'Hidden' in their properties, allowing them to act as invisible data storage for your JavaScript dialogs.
WPS PDF Editor

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. 1. Open your PDF form in WPS Office: Launch WPS Office and open the PDF document that contains your interactive form fields.
  2. 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. 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.
Simplified PDF form filling and field management without complex custom codingHighly compatible with standard Adobe PDF documents and Microsoft Office formatsLightweight, fast, and completely free to download
microsoft office alternative - wps office

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.