Use Acrobat JavaScript to Convert a Total Score to a Range
Question details
Convert a total score from 1 to 45 into a result of 1, 2, or 3 using Acrobat JavaScript.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Calculate a score range from a total entered in a PDF form.
- Observed behavior
- Scores of 1–15 should return 1, scores of 16–30 should return 2, and scores of 31–45 should return 3.
Open an editable PDF form in Acrobat and identify the field that holds the total score. The example below assumes that field is named Total and that scores are whole numbers.
Add a custom calculation script to the result field
Use this method to display the corresponding range automatically in an Acrobat form field.
In Acrobat, open the PDF and choose Prepare a form. Create or identify a result field separate from the Total field.
Open the result field's Properties, select the Calculate tab, and choose Custom calculation script. Click Edit.
Paste this script into the editor and save it: var raw = this.getField("Total").valueAsString.replace(/^\s+|\s+$/g, ""); var total = Number(raw); if (!/^\d+$/.test(raw) || total < 1 || total > 45) { event.value = ""; } else if (total <= 15) { event.value = 1; } else if (total <= 30) { event.value = 2; } else { event.value = 3; }
Close the form editor and enter values in Total. Check that 15 returns 1, 16 and 30 return 2, and 31 and 45 return 3.

Calculate score ranges in WPS Spreadsheet
For a spreadsheet-based alternative, use a formula to classify scores in WPS Office. It is a free, lightweight suite with a familiar interface and Microsoft Office format compatibility for easy migration. It does not replace the Acrobat JavaScript form calculation.

Frequently Asked Questions
Where do I put the JavaScript in Acrobat?
In Prepare a form, open the result field's Properties, select Calculate, and click Edit under Custom calculation script.
What happens if the score is outside 1–45?
The example script leaves the result field blank for scores outside that range, as well as for blank or non-whole-number entries.
What if my total field has a different name?
Replace Total in this.getField("Total") with the exact name shown in the input field's Properties.
Can I calculate the ranges in a spreadsheet instead?
Yes. In WPS Spreadsheet, enter a score in A2 and use a formula in another cell to assign a range. This is a spreadsheet alternative, not an Acrobat form script.




