Others

Use Acrobat JavaScript to Convert a Total Score to a Range

Steven ParkerSteven Parker Nov 18, 2026 869 views

Question details

Convert a total score from 1 to 45 into a result of 1, 2, or 3 using Acrobat JavaScript.

Convert a Total Score to a Range with 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.
Before you start

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.

Solution 1Recommended

Add a custom calculation script to the result field

Use this method to display the corresponding range automatically in an Acrobat form field.

1
Open the form editor

In Acrobat, open the PDF and choose Prepare a form. Create or identify a result field separate from the Total field.

2
Open the calculation script

Open the result field's Properties, select the Calculate tab, and choose Custom calculation script. Click Edit.

3
Enter the script

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

4
Test the result

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.

Add a custom calculation script to the result field
Invalid scores: The script clears the result for blank entries, non-whole numbers, and values outside 1–45. Replace Total in the script if your input field has a different name.
Free Microsoft Office alternative

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.

Classify scores with spreadsheet formulasOpen and save Microsoft Excel XLSX filesUse a familiar spreadsheet interfaceWork with a free, lightweight office suite
microsoft office alternative - wps office

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.