PDF Editing Issues

How to Calculate a 5% Credit Card Fee in a Fillable PDF Form

Olivia MillerOlivia Miller Nov 2, 2026 869 views

Question details

The user needs to dynamically calculate a 5% credit card surcharge based on specific total fields when a payment checkbox is toggled in a PDF form.

How to Calculate a 5% Credit Card Fee in a Fillable PDF Form
Product
PDF Editor
Device & OS
not provided
Scenario
Creating a dynamic invoice or payment form where a fee (like a 5% surcharge or 7% sales tax) is automatically applied only if the user selects the corresponding checkbox.
Observed behavior
The form needs a custom script that correctly checks the checkbox export value, sums up the required subtotal fields, applies the percentage multiplier, and outputs the result in the designated fee field.
Before you start

Ensure your PDF editor supports JavaScript for form fields and take note of the exact field names for your checkbox and total fields, as they are case-sensitive.

Solution 1Recommended

Use Custom JavaScript to Calculate Conditional Fees

Apply a custom calculation script to the fee field that verifies the checkbox status before performing the percentage calculation.

In fillable PDF forms, conditional logic such as applying a fee only when a checkbox is ticked requires a custom JavaScript calculation. You can write a script that checks if the checkbox's export value is active, adds up your subtotal fields, and multiplies the sum by your desired percentage.

1
Open Field Properties

Open your PDF document in form editing mode. Right-click the text field where you want the calculated fee to appear and select Properties.

2
Select Custom Calculation

Navigate to the Calculate tab within the Properties window. Select the option for 'Custom calculation script' and click the Edit button.

3
Enter the JavaScript Code

Input the script to check the checkbox and calculate the total. For example: var total = 0; if (this.getField("Credit").value != "Off") { total += Number(this.getField("Total189").valueAsString); total += Number(this.getField("Total212").valueAsString); } event.value = total * 0.05;

4
Match Your Field Names

Replace "Credit", "Total189", and "Total212" in the script with the exact names of the checkbox and subtotal fields used in your actual PDF document.

5
Save and Test

Click OK to save the script, close the properties dialog, and exit form editing mode. Toggle the checkbox to test if the 5% fee calculates correctly.

Use Custom JavaScript to Calculate Conditional Fees
Adapting for Sales Tax: This exact logic can be used for state sales tax. For a 7% sales tax, simply change the checkbox name in the script to your tax checkbox (e.g., "MS"), update the subtotal field names, and change the multiplier from 0.05 to 0.07.
Powerful PDF Form Editor

Create and Edit Smart Fillable PDF Forms with WPS Office

WPS Office offers comprehensive PDF tools to easily create interactive forms. You can insert text fields, checkboxes, and set up advanced calculation scripts to fully automate your invoices and payment forms.

  1. 1. Open your PDF: Launch WPS Office and open your PDF document.
  2. 2. Access Form Tools: Navigate to the Form tab to view all interactive form controls.
  3. 3. Add Fields: Insert your desired Checkbox and Text Fields onto the document.
  4. 4. Configure Properties: Right-click the target field, open Properties, and configure your calculation scripts under the Calculate tab.
Easily insert interactive text fields, checkboxes, and dropdown menusFully compatible with standard Adobe PDF form scripts and calculationsLightweight application with a clean, user-friendly interfaceCross-platform support for managing PDFs on Windows, Mac, and mobile
QA img-9

Frequently Asked Questions

Why is my PDF calculation script not returning any result?

This usually happens if the field names in your JavaScript do not match the exact names of the fields in your form. Verify your spelling and capitalization. Additionally, check that the export value of your checkbox is correctly configured and not defaulting to "Off" when checked.

How do I make the fee field remain blank if the checkbox is unchecked?

To leave the field blank instead of showing a zero, add an else statement to your JavaScript: else { event.value = ""; }. This ensures the field clears out when the payment option is deselected.

Can I calculate a different percentage like a 7% state sales tax?

Yes. In your custom calculation script, locate the multiplication line (e.g., event.value = total * 0.05) and update the decimal multiplier. Change 0.05 to 0.07 to calculate a 7% tax.

How can I subtract a discount using custom JavaScript?

You can follow the same conditional logic but change the mathematical operation. Sum up your totals, calculate the discount amount (e.g., total * 0.10 for 10%), and set the event.value to multiply by a negative or simply subtract it from a grand total calculation.