Other PDF Issues

How to Create an Acrobat JavaScript Bonus Calculation Based on a Checkbox

Camila MilosovichCamila Milosovich Nov 5, 2026 869 views

Question details

The user needs to dynamically add a bonus to a text field when a checkbox is selected in a PDF form, and remove it when cleared, using JavaScript tracking logic to prevent duplicate calculations.

How to Create an Acrobat JavaScript Bonus Calculation Based on a Checkbox
Product
PDF Forms
Device & OS
not provided
Scenario
Building an interactive PDF form that relies on checkboxes to trigger conditional mathematical calculations in other fields.
Observed behavior
Without specific programming logic, scripts cannot automatically infer prior changes. A dedicated tracking method must be used so the calculation does not apply the bonus multiple times during recalculation.
Before you start

Ensure you have access to a PDF editor with advanced form editing and JavaScript capabilities, and back up your PDF file before modifying its calculation scripts.

Solution 1Recommended

Use a Tracking Variable in Your JavaScript Action

Implement explicit tracking logic in your checkbox script to monitor whether the bonus has already been applied to the total text field.

A script only executes the exact instructions it is given and cannot infer prior states. To prevent a bonus from being added multiple times when a checkbox is toggled, you must program logic to remember the state of the bonus. This is typically done by utilizing a hidden text field or defining a document-level tracking variable that updates whenever the checkbox changes.

1
Enter Form Editing Mode

Open your PDF document and activate the form editing tools to display all interactive fields.

2
Access Checkbox Properties

Right-click the specific checkbox that triggers the bonus, select 'Properties', and navigate to the 'Actions' tab.

3
Add a Custom JavaScript Action

Under the 'Select Action' dropdown, choose 'Run a JavaScript', choose the trigger action (such as 'Mouse Up'), and click the 'Add' button.

4
Input the Calculation and Tracking Script

Write logic to check the checkbox value. If it is checked and your tracking variable indicates the bonus hasn't been applied, add the bonus to the target text field and update the tracking variable. If it is unchecked, subtract the bonus and reset the variable.

5
Verify Calculation Order

Save your changes and test the form. If you have multiple calculated fields, verify your PDF editor's calculation order settings to ensure the base total calculates before the checkbox script adds the bonus.

Use a Tracking Variable in Your JavaScript Action
Calculation Order Matters: Recalculation order and manual edits can directly affect your final result. Always test your scripts by repeatedly checking and unchecking the box to ensure the total remains accurate.
Interactive PDF Form Tools

Create and Manage Interactive PDF Forms with WPS Office

WPS Office provides an intuitive suite of PDF tools, allowing you to easily create interactive forms, add checkboxes, and manage your document's form fields seamlessly.

  1. 1. Open WPS Office PDF: Launch WPS Office and open your PDF document within the PDF editor.
  2. 2. Navigate to the Form Tab: Click on the 'Form' tab in the top ribbon to access the interactive form controls.
  3. 3. Insert Form Controls: Select the 'Check Box' or 'Text Field' tools and draw them onto your document layout.
  4. 4. Configure Properties: Double-click the inserted fields to configure their names, appearance, and default states, then save your interactive PDF.
Easily insert interactive checkboxes, radio buttons, and text fieldsIntuitive form-building interface for precise document controlFully compatible with Microsoft Office and standard Adobe PDF formats for seamless sharing
microsoft office alternative - wps office

Frequently Asked Questions

Why does my PDF script add the bonus multiple times?

Scripts cannot infer past actions automatically. If you do not include logic to track whether the bonus has already been added, the script will add the value every time the calculation is triggered. Use a tracking variable to resolve this.

How can I hide a tracking field from users?

You can insert a text field specifically for tracking the state, right-click it, select 'Properties', and set its form field visibility to 'Hidden'. This keeps the data accessible to your JavaScript while keeping the layout clean and preventing it from being printed.

Does WPS Office support editing PDF forms?

Yes, WPS Office features a dedicated Form tab that allows you to add, edit, and configure interactive form fields like checkboxes, text boxes, and dropdown menus seamlessly.