How to Create a Self-Marking PDF Worksheet with JavaScript
Question details
The user needs to create an interactive PDF workbook that automatically evaluates student answers and displays correct or incorrect feedback.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Creating educational materials, quizzes, or interactive workbooks where instant grading feedback is required.
- Observed behavior
- The goal is to configure PDF form text fields to run calculation scripts that compare user input against predefined correct answers and automatically display feedback.
Ensure you are using a PDF editor that supports advanced form creation and custom JavaScript calculations, and map out the expected correct answers for your worksheet questions beforehand.
Use a Custom Calculation Script in a Feedback Field
Create linked text fields to capture the student's answer and display the automated feedback using an Acrobat JavaScript calculation.
PDF forms do not have native 'self-marking' toggles, but you can achieve this by using two fields per question: one for the student's input and another to evaluate that input via a custom JavaScript calculation.
You will need to assign the script to the feedback field so that it updates dynamically as soon as the student clicks out of the answer field.
Open your PDF in form editing mode. Insert a Text Field where the student will type their answer. Name this field specifically, for example, 'Question1'.
Insert a second Text Field next to the answer field to act as the feedback display. Name this field 'Feedback1' and set it to 'Read Only' in its properties so students cannot edit the feedback directly.
Open the properties of the 'Feedback1' field and navigate to the 'Calculate' tab. Select 'Custom calculation script' and click 'Edit'. Enter the following JavaScript: var a = this.getField('Question1').value; if (a) { event.value = (a == '7') ? 'Correct' : 'Wrong'; } else { event.value = ''; }
Exit form editing mode and type the correct answer (in this example, '7') into 'Question1'. Click away to trigger the calculation. 'Feedback1' should now automatically display 'Correct'.

Build Interactive PDFs Easily with WPS Office
WPS PDF provides a comprehensive set of form-building tools that allow you to create interactive, self-marking worksheets. You can easily insert text fields, checkboxes, and integrate JavaScript to create dynamic educational resources.
- 1. Open your PDF in WPS: Launch WPS Office and open your PDF document using the WPS PDF editor.
- 2. Access the Form Tab: Navigate to the 'Form' tab on the top ribbon to reveal all interactive field tools.
- 3. Insert Form Fields: Click 'Text Field' and draw the fields for student answers and feedback directly onto your document.
- 4. Apply Calculations: Right-click the feedback field, select 'Properties', go to the 'Calculate' tab, and add your custom JavaScript to automate grading.

Frequently Asked Questions
Can I make the grading case-insensitive?
Yes. In your JavaScript code, use the toLowerCase() method on the student's input. For example: if (a.toLowerCase() == 'paris') will mark both 'Paris' and 'paris' as correct.
How do I hide the feedback field until the student enters an answer?
The script provided naturally handles this. The condition 'if (a)' checks if the answer field is empty. If it is empty, the 'else' block executes 'event.value = "";', which keeps the feedback field blank until input is detected.
Can I calculate a total score for the entire worksheet?
Yes. You can create hidden text fields that assign a value (like 1 or 0) based on correct answers, and then create a 'Total Score' field at the bottom of the document with a calculation script that sums up all the hidden score fields.
Will these JavaScript calculations work on mobile PDF readers?
JavaScript support varies widely among mobile PDF readers. While it works reliably on desktop applications like WPS Office and Adobe Acrobat, some basic mobile PDF viewers do not support custom form calculations.




