How to Calculate Score Ratings with JavaScript in PDF Forms
Question details
The user needs to create a calculation script in a PDF form to assign text ratings (Poor, Good, or Great) based on a numerical percentage score ranging from 0 to 100.

- Product
- Adobe Acrobat PDF Forms
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form that automatically grades or evaluates numerical input and outputs a corresponding text label in a dedicated field.
- Observed behavior
- The user requires the correct JavaScript syntax and field property configuration to ensure the score evaluates correctly (0-49 for Poor, 50-80 for Good, 81-100 for Great) and updates dynamically.
Ensure your PDF form contains a numerical input field (e.g., named 'Percent') and a target text field (e.g., named 'OBscore') where the text rating will be displayed. You will need access to the form editing tools and JavaScript properties.
Apply a Custom Calculation JavaScript to the Target Field
Add a custom calculation script to your output text field so it automatically evaluates the percentage score and updates the text rating whenever the score changes.
In interactive PDF forms, custom calculation scripts run automatically whenever any field value changes. By placing this JavaScript inside the output field, the rating updates dynamically.
Open your PDF form in Edit mode. Right-click the target text field where you want the rating to appear (e.g., 'OBscore') and select 'Properties'.
In the Field Properties dialog box, click on the 'Calculate' tab to view the calculation options for this specific field.
Select the 'Custom calculation script' option and click the 'Edit' button to open the JavaScript editor window.
Type the following code into the editor: var score = this.getField("Percent").value; if (score < 50) { event.value = "Poor"; } else if (score <= 80) { event.value = "Good"; } else { event.value = "Great"; }
Click 'OK' to save the script, then close the Field Properties dialog. Exit Edit mode and test the form by typing a number between 0 and 100 into the 'Percent' field.
Manage and Fill PDF Forms with WPS Office
While creating advanced JavaScript calculations requires specialized form-building tools, WPS Office provides a robust, lightweight, and free solution for filling interactive PDF forms, editing PDF text, and handling standard office documents.
- 1. Download and Install: Download WPS Office for free from the official website and follow the simple installation instructions.
- 2. Open Your PDF Form: Launch WPS Office and click 'Open' to select your interactive PDF form.
- 3. Fill and Save: Easily type into form fields, apply electronic signatures, and save the completed document.

Frequently Asked Questions
Why is my PDF script returning 'Great' even when I input a low percentage?
If your input field is formatted as a Percentage field, the underlying data ranges from 0 to 1 (e.g., 50% is 0.5), not 0 to 100. You need to update your script to check against decimals (use < 0.5 instead of < 50).
Can I write this script using Java instead of JavaScript?
No. Interactive PDF forms exclusively use JavaScript for custom calculation scripts. Java is an entirely different programming language and will not work within PDF form fields.
How do I ensure the text rating updates automatically when the score changes?
You must place the JavaScript code in the 'Calculate' tab of the target field's properties, rather than as an action triggered by a mouse click (like 'On Blur' or 'Mouse Up'). Calculation scripts automatically trigger whenever any field value in the form is modified.




