PDF Editing Issues

How to Calculate Score Ratings with JavaScript in PDF Forms

Huda QurayshiHuda Qurayshi Nov 3, 2026 870 views

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.

How to Calculate Score Ratings with JavaScript in PDF Forms
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Field Properties

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'.

2
Navigate to the Calculate Tab

In the Field Properties dialog box, click on the 'Calculate' tab to view the calculation options for this specific field.

3
Enable Custom Calculation

Select the 'Custom calculation script' option and click the 'Edit' button to open the JavaScript editor window.

4
Enter the JavaScript Code

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"; }

5
Save and Test

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.

Important Note on Percentage Formatting: If your 'Percent' field is strictly formatted as a Percentage data type in Acrobat, its underlying value actually ranges from 0 to 1, not 0 to 100. In this case, you must modify your script to check against decimals: use '< 0.5' for Poor and '<= 0.8' for Good.
Free Microsoft Office alternative

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. 1. Download and Install: Download WPS Office for free from the official website and follow the simple installation instructions.
  2. 2. Open Your PDF Form: Launch WPS Office and click 'Open' to select your interactive PDF form.
  3. 3. Fill and Save: Easily type into form fields, apply electronic signatures, and save the completed document.
Fully compatible with standard interactive PDF forms and Microsoft Office document formats.Easily view, fill, sign, and print interactive PDF forms with a highly intuitive user interface.Lightweight software that runs quickly and consumes minimal system resources.Includes powerful built-in tools to convert PDFs into editable Word, Excel, and PowerPoint files.
QA img-9

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.