How to Calculate a 5% Credit Card Fee in a Fillable PDF Form
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.

- 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.
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.
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.
Open your PDF document in form editing mode. Right-click the text field where you want the calculated fee to appear and select Properties.
Navigate to the Calculate tab within the Properties window. Select the option for 'Custom calculation script' and click the Edit button.
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;
Replace "Credit", "Total189", and "Total212" in the script with the exact names of the checkbox and subtotal fields used in your actual PDF document.
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.

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. Open your PDF: Launch WPS Office and open your PDF document.
- 2. Access Form Tools: Navigate to the Form tab to view all interactive form controls.
- 3. Add Fields: Insert your desired Checkbox and Text Fields onto the document.
- 4. Configure Properties: Right-click the target field, open Properties, and configure your calculation scripts under the Calculate tab.

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.




