How to Create a Radio Button Discount Script in Acrobat
Question details
The user wants to write a JavaScript snippet for a radio button in an Acrobat PDF form to apply a 5% discount to a calculated Grand Total field.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating advanced interactive PDF forms that require custom calculation logic based on user selection (e.g., applying a pickup discount).
- Observed behavior
- Needs the exact JavaScript logic and setup instructions to integrate a radio button selection with an existing Grand Total calculation without breaking the calculation order.
Ensure you have a desktop version of Adobe Acrobat Pro, as standard reader applications do not allow you to author or edit form field calculation scripts. Back up your PDF before applying custom JavaScript.
Apply Custom Calculation Script to the Grand Total Field
Use JavaScript within the Grand Total field's calculation properties to check the value of the radio button and apply the 5% discount accordingly.
Instead of attaching the calculation script to the radio button itself, it is best practice to place the calculation logic directly inside the Grand Total field. This ensures the total dynamically updates whenever any relevant field in the form changes.
Name your radio button group (e.g., 'DeliveryOption') and ensure the specific 'Pickup' choice has a defined export value (e.g., 'Pickup').
Enter Form Editing mode. Right-click your 'Grand Total' field, select 'Properties', and navigate to the 'Calculate' tab.
Select the 'Custom calculation script' option and click the 'Edit' button to open the JavaScript editor.
Write your code to calculate the base total first. Then, add an if-statement to check the radio button: `if (this.getField('DeliveryOption').value == 'Pickup') { event.value = baseTotal * 0.95; } else { event.value = baseTotal; }`.
Exit the editor and go to 'More' > 'Field Calculation Order' in the form tools. Ensure your subtotal fields calculate before the Grand Total field to prevent delayed updates.

Consult the Adobe Acrobat Community Forum
If your PDF form involves highly complex nested calculations or conflicts with existing scripts, consulting experts on the official Adobe Acrobat forum is highly recommended.
Create and Manage PDF Forms Easily with WPS Office
While Acrobat offers extensive JavaScript support for complex calculations, WPS Office provides an incredibly intuitive, lightweight PDF editor for creating forms, adding text fields, and managing interactive elements seamlessly.
- 1. Open Your PDF: Launch WPS Office and open your PDF document within the built-in PDF editor.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive element toolkit.
- 3. Add Form Fields: Click on the radio button, checkbox, or text field icons, and click on your document page to place them.
- 4. Edit Properties: Double-click the inserted fields to configure their names, export values, and appearance.
- 5. Save the Interactive Form: Save your document. The interactive elements will be preserved and functional for any user filling out the form.

Frequently Asked Questions
Why is my PDF Grand Total calculating one step behind?
This usually happens because of an incorrect field calculation order. In your PDF editor, check the calculation order list and move the Grand Total field to the very bottom so it calculates last, after all other fields have finished processing.
What export value should I set for my discount radio button?
You can set the export value to anything descriptive, such as 'Pickup' or 'Yes'. Your JavaScript just needs to exactly match this string when checking the field's value (e.g., `if (this.getField('Group1').value == 'Pickup')`).
Do I add the JavaScript to the radio button or the total field?
For discounts affecting a total, it is highly recommended to add the Custom Calculation Script directly to the Grand Total field rather than the radio button. This ensures the total updates correctly whenever any dependent field changes.




