PDF Editing Issues

How to Use JavaScript to Convert Scores to Ratings in PDF Forms

Anum MushtaqAnum Mushtaq Nov 10, 2026 870 views

Question details

The user wants to automatically convert a raw score between 0 and 100 into a 1 to 5 rating scale within an interactive PDF form.

How to Use JavaScript to Convert Scores to Ratings in PDF Forms
Product
PDF Editors
Device & OS
not provided
Scenario
Creating interactive PDF forms that require automatic grading or rating calculations based on a user's total score input.
Observed behavior
Standard PDF form features only perform basic math functions, requiring custom JavaScript conditional logic to process score-to-rating conversions accurately.
Before you start

Ensure you have a PDF editor with form editing and JavaScript capabilities installed, and that you have already created the text fields for both the 'Total Score' and the final 'Rating'.

Solution 1Recommended

Apply Custom Calculation Script in Your PDF Form Designer

Use conditional JavaScript to evaluate the total score boundary and output the corresponding rating value into your target field.

Adding customized JavaScript allows for complex logic, such as grading rubrics, directly inside an interactive PDF file.

The logic checks the number in the total score field sequentially and updates the rating field's value accordingly.

1
Enter form preparation mode

Open your interactive PDF form in your PDF designer (such as Adobe Acrobat) and enter 'Prepare Form' or 'Edit Form' mode.

2
Access field properties

Right-click the text field where the 1-5 rating should appear (for example, 'Your Rating' or 'Your Score') and select 'Properties' from the context menu.

3
Enable custom calculation

Navigate to the 'Calculate' tab in the Properties window and select the radio button labeled 'Custom calculation script'.

4
Insert the JavaScript code

Click the 'Edit' button and paste the following conditional snippet: var total = Number(this.getField('Total Score').value); if (total >= 0 && total <= 20) event.value = 1; else if (total <= 40) event.value = 2; else if (total <= 60) event.value = 3; else if (total <= 80) event.value = 4; else if (total <= 100) event.value = 5;

5
Save and test

Verify that the field name referenced in the script ('Total Score') exactly matches the name of your raw score input field. Click 'OK', close the properties, and test your form by typing a number into the score field.

Apply Custom Calculation Script in Your PDF Form Designer
Field Name Sensitivity: JavaScript is case-sensitive. Verify that the spelling, capitalization, and spacing of 'Total Score' perfectly matches your form's actual field property name, or the script will fail to execute.
Efficient PDF Management

Interact with and Manage PDF Forms using WPS Office

While adding backend scripts simplifies form calculations, interacting with, filling, and managing these complex PDFs requires a reliable viewer and editor. WPS PDF effortlessly processes standard interactive PDF forms to streamline your workflow.

  1. 1. Download WPS Office: Download and launch WPS Office for free on your computer or mobile device.
  2. 2. Open your PDF file: Navigate to the main dashboard, select the 'PDF' tab, and open the interactive PDF form you want to fill or review.
  3. 3. Fill the form fields: Click on the designated form fields to input your data. Any standard calculation scripts embedded in the file will execute and populate results automatically.
  4. 4. Save and share: Once completed, safely export or share your filled document instantly from within the interface.
Seamlessly fill, view, and interact with complex PDF forms containing custom scripts.Easily edit text, images, and pages within your PDF documents without altering formatting.High format compatibility with Adobe Acrobat PDF and Microsoft Office documents.Lightweight application that loads fast and won't slow down your device.
QA img-9

Frequently Asked Questions

Why isn't my PDF form calculating the rating automatically?

This usually happens if the field name referenced in the JavaScript (like 'Total Score') does not perfectly match the actual property name of the input field. Also, ensure you have enabled JavaScript execution in your PDF viewer's security preferences.

Can I change the score ranges in the custom calculation script?

Yes. You can edit the numbers in the if and else if conditions to match your specific grading rubric. For instance, if you want a score of 50 to output a rating of 2, you would adjust the script's thresholds accordingly.

Does WPS PDF support viewing PDFs with JavaScript calculations?

Yes, WPS PDF supports standard interactive PDF forms. When you input numeric values into fields that rely on properly formatted embedded calculation scripts, the conditional outputs will function smoothly.

How do I hide the rating field if the total score is empty?

You can update the script to check if the total score field is blank before running the grading logic. Add `if (this.getField('Total Score').valueAsString == '') { event.value = ''; } else { ... }` wrapping your custom calculation script.