How to Use JavaScript to Convert Scores to Ratings in PDF Forms
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.

- 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.
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'.
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.
Open your interactive PDF form in your PDF designer (such as Adobe Acrobat) and enter 'Prepare Form' or 'Edit Form' mode.
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.
Navigate to the 'Calculate' tab in the Properties window and select the radio button labeled 'Custom calculation script'.
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;
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.

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. Download WPS Office: Download and launch WPS Office for free on your computer or mobile device.
- 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. 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. Save and share: Once completed, safely export or share your filled document instantly from within the interface.

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.




