How to Calculate Test Score Percentage with JavaScript in Acrobat
Question details
The user wants to automatically calculate a quiz or test percentage in an Acrobat PDF form based on the number of correct answers inputted.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form for a test where a specific field needs to dynamically compute and display the final percentage score.
- Observed behavior
- A custom JavaScript is needed to divide the correct answer count by the total question count and display the result correctly as a percentage.
Ensure you have the 'Prepare Form' tool enabled in Adobe Acrobat and note down the exact, case-sensitive name of the field where the user inputs the correct answers.
Add a Custom Calculation Script to the Percentage Field
Use Acrobat's custom calculation properties to apply a JavaScript snippet that calculates the percentage score.
By utilizing custom JavaScript in PDF form fields, you can perform mathematical calculations instantly. The script retrieves the value from the score field, divides it by the total number of questions, and outputs the result.
Open your PDF document in Adobe Acrobat, navigate to the Tools menu, and select 'Prepare Form' to enter form editing mode.
Right-click on the text field where you want the percentage to be displayed, then click 'Properties' from the context menu.
Go to the 'Calculate' tab, select 'Custom calculation script', and click the 'Edit' button. Enter the following code: event.value = Number(this.getField("CorrectAnswers").value) / 20; (replace 'CorrectAnswers' with your actual score field name, and '20' with your test's total number of questions).
Switch to the 'Format' tab, click on the 'Select format category' drop-down menu, choose 'Percentage', and then click 'Close' to save your changes.

Manage and Fill Interactive PDF Forms with WPS Office
While setting up complex JavaScript calculations requires advanced PDF creation tools, WPS Office provides a lightweight, highly compatible PDF editor perfect for viewing, filling, and managing interactive PDF forms seamlessly across all your devices.
- 1. Launch WPS PDF: Open WPS Office and select the 'PDF' module to load your interactive form.
- 2. Access interactive fields: Click into any highlighted text field or checkbox to enter your data or test scores.
- 3. Save and share: Once the form is filled out, click 'Menu' > 'Save As' to secure your inputted data, or quickly share it via email.

Frequently Asked Questions
Why is my PDF form calculation returning an error or showing nothing?
This typically occurs if the field name referenced in your JavaScript (e.g., "CorrectAnswers") does not exactly match the actual name of the input field. Field names in JavaScript are strictly case-sensitive.
Do calculation scripts in PDFs update automatically?
Yes, as long as the PDF viewer supports JavaScript, the calculation field will automatically update its value as soon as you enter the correct answer count and click outside of the input field.
How do I adjust the script for a quiz with a different number of questions?
Simply change the divisor number at the end of the script to match your total number of questions. For instance, if your test has 50 questions, change '/ 20' to '/ 50'.
Can I perform this JavaScript setup in a standard web browser?
No, while many web browsers can display basic PDF forms, creating or editing the underlying JavaScript calculation properties requires a dedicated PDF editor like Adobe Acrobat Pro.




