How to Use a Custom PDF Form Script for Percentages Based on Total Score
Question details
The user needs to configure a PDF form to automatically assign a specific decimal or percentage value (e.g., 0.06 or 0.03) based on whether another field's total score is above or below 100.

- Product
- PDF Document
- Device & OS
- not provided
- Scenario
- Creating a dynamic PDF form where field values change automatically based on calculations and conditional statements from other form fields.
- Observed behavior
- The Percentage field needs to automatically evaluate the Total Score field and output either 0.06 (if 100 or above) or 0.03 (if below 100).
Ensure you have the exact name of your 'Total Score' field and verify whether your target output field is formatted as a standard Number or specifically as a Percentage, as this changes the required decimal values in the script.
Apply a Custom JavaScript Calculation Script
Add a concise conditional JavaScript statement to your Percentage field's calculation properties to automate the value assignment.
You can use a simple ternary operator in JavaScript to evaluate the Total Score field and assign the corresponding decimal value. Pay close attention to whether the field is explicitly formatted as a percentage in your PDF editor, as the system requires a smaller decimal value for correct display in that format.
Open your PDF form in edit mode, right-click the target Percentage field, and select 'Properties' from the context menu.
In the Properties window, select the 'Calculate' tab to view the formula options for the field.
Select the 'Custom calculation script' option, click the 'Edit' button, and enter the following code: event.value = +getField('Total Score').value >= 100 ? 0.06 : 0.03;
If your field is explicitly formatted as a Percentage in the 'Format' tab, adjust the script values to smaller decimals so they display properly: event.value = +getField('Total Score').value >= 100 ? 0.0006 : 0.0003;
Click 'OK', close the properties window, and enter a test number in the 'Total Score' field to verify the calculation works.

Edit and Manage PDF Forms Easily with WPS PDF
WPS Office provides a comprehensive PDF editor that allows you to easily manage interactive PDF forms, edit document text, and handle form properties without requiring expensive specialized software.
- 1. Open WPS Office: Launch WPS Office and navigate to the PDF tab.
- 2. Import Your PDF Document: Open your interactive PDF form document within the application.
- 3. Fill or Edit Forms: Use the integrated PDF tools to fill out fields; the software will process embedded form calculations smoothly.
- 4. Save and Export: Save your completed PDF document securely or share it directly from the app.

Frequently Asked Questions
Why is my PDF form calculation script returning a blank or zero value?
This typically happens if the field name referenced in your script (like 'Total Score') does not exactly match the actual name of the field in your form's properties. Double-check for typos, extra spaces, or case differences, as JavaScript is case-sensitive.
Do I need to change my script if my field is formatted as a percentage?
Yes. Most PDF readers multiply the underlying value by 100 when a field is formatted as a percentage. To display 6%, your script should return 0.06 if formatted as a standard number, but it must return 0.0006 if the field formatting is set to Percentage.
How do I handle blank fields in my PDF calculation script so it doesn't default to the lower percentage automatically?
If the total field might be empty upon opening the document, you can add an 'if' condition to check if the field is blank before running the calculation. For example, check if the field string length is greater than zero before applying the ternary operator.




