How to Create an Acrobat JavaScript Formula for Score-Based Percentages
Question details
The user needs an Acrobat JavaScript calculation formula to return specific percentage strings based on an inputted numerical score.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating a custom calculation script for a PDF form field to evaluate an overall score and assign a percentage output.
- Observed behavior
- The form needs to dynamically display '100%' for scores above 199, '80%' for scores from 180 to 199, and remain blank for any lower scores.
Ensure that the source field you are referencing (e.g., 'Overall score') is properly named and contains a valid numerical value before applying the calculation script to your target field.
Use Explicit Logical Comparisons in a Custom Calculation Script
Implement an if-else statement ensuring the score variable is explicitly stated on both sides of the logical AND (&&) operator.
When writing custom calculation scripts in Acrobat, a common syntax error is failing to repeat the variable being compared in a logical range.
Writing 'score >= 180 && <= 199' is invalid in JavaScript. You must explicitly declare the variable on both sides, like 'score >= 180 && score <= 199'.
Open your PDF form in editing mode, right-click the target field where the percentage should appear, and select 'Properties'.
In the Properties dialog, go to the 'Calculate' tab and select the 'Custom calculation script' option.
Click the 'Edit' button and paste the following code: var score = Number(this.getField("Overall score").valueAsString); if (score > 199) { event.value = "100%"; } else if (score >= 180 && score <= 199) { event.value = "80%"; } else { event.value = ""; }
Click 'OK' to save the script. Exit form editing mode and test the functionality by entering different values into the 'Overall score' field.

Edit and Manage PDF Forms with WPS PDF
WPS Office provides a comprehensive suite of PDF tools, allowing you to easily fill out, edit, and manage interactive PDF forms with advanced features without needing heavy software.
- 1. Launch WPS PDF: Open WPS Office and click on the 'PDF' tab to launch the built-in PDF editor.
- 2. Open Your PDF: Select and open your interactive PDF document from your local files.
- 3. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access form editing and management tools.
- 4. Fill and Save: Fill out, edit, or adjust your PDF form fields as needed, then click 'Save' to preserve your changes.

Frequently Asked Questions
Why is my JavaScript calculation returning an error in the PDF?
This typically happens due to incorrect syntax. A common mistake is writing `if (score >= 180 && <= 199)`. In JavaScript, you must explicitly declare the variable on both sides of the `&&` operator: `if (score >= 180 && score <= 199)`.
How do I correctly reference another field in an Acrobat calculation script?
You can retrieve the value of another field using the `this.getField("FieldName").value` or `.valueAsString` method. Make sure the field name is enclosed in quotation marks and spelled exactly as it appears in the properties.
Should I set the target field format to Percentage?
If your script outputs a text string containing a percent sign (like "80%"), you should leave the field's Format tab set to "None". Setting it to "Percentage" is only necessary if your script returns a raw decimal value (like 0.8).




