PDF Editing Issues

How to Calculate Test Score Percentage with JavaScript in Acrobat

Ayan MasoodAyan Masood Nov 10, 2026 870 views

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.

How to Calculate Test Score Percentage with JavaScript in Acrobat
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the Prepare Form tool

Open your PDF document in Adobe Acrobat, navigate to the Tools menu, and select 'Prepare Form' to enter form editing mode.

2
Access field properties

Right-click on the text field where you want the percentage to be displayed, then click 'Properties' from the context menu.

3
Input the custom calculation script

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).

4
Format as a percentage

Switch to the 'Format' tab, click on the 'Select format category' drop-down menu, choose 'Percentage', and then click 'Close' to save your changes.

Add a Custom Calculation Script to the Percentage Field
Alternative Number Formatting: If you prefer not to use the built-in Percentage format, you can multiply the result by 100 within the script itself: event.value = (Number(this.getField("CorrectAnswers").value) / 20) * 100; and simply set the Format tab to 'Number'.
Powerful PDF Editor

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. 1. Launch WPS PDF: Open WPS Office and select the 'PDF' module to load your interactive form.
  2. 2. Access interactive fields: Click into any highlighted text field or checkbox to enter your data or test scores.
  3. 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.
Easily fill out interactive PDF forms and save your progress without data loss.Highly compatible with standard PDF formats created in Adobe Acrobat.Convert PDFs to Word or Excel to perform complex formulas directly in spreadsheets.Lightweight, fast-loading, and free alternative to heavy PDF software.
microsoft office alternative - wps office

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.