PDF Editing Issues

How to Change PDF Form Field Colors for Correct Answers

Kushani NimanthikaKushani Nimanthika Nov 3, 2026 868 views

Question details

The user needs to create a self-grading PDF assignment that compares inputted form field values with correct answers upon clicking a button, altering the text color of incorrect answers while limiting submissions.

How to Change PDF Form Field Colors for Correct Answers
Product
PDF Editor
Device & OS
not provided
Scenario
Creating an interactive, self-grading PDF assessment for students that provides immediate visual feedback.
Observed behavior
The goal is to automatically evaluate input fields against an array of correct answers, changing the text color of incorrect responses to red, keeping correct answers black, and restricting total attempts to two.
Before you start

Ensure your PDF editing software supports JavaScript for form fields. You will need to add a custom script to a button action to automatically evaluate the answers.

Solution 1Recommended

Use JavaScript to Evaluate Answers and Change Text Color

Add a custom JavaScript action to a button to compare input values against an array of correct answers and adjust the text color accordingly.

To achieve self-grading functionality, you can write a short JavaScript loop that targets your question fields. The script compares the student's input to a predefined list of correct answers.

If the answers do not match, the text color changes to red to indicate an error. If they match, the text remains black.

1
Add a submission button

Insert a button form field into your PDF document that students will click to submit or check their answers.

2
Access button properties

Double-click the button to open its properties, navigate to the Actions tab, and select 'Run a JavaScript' as the action for the 'Mouse Up' trigger.

3
Insert the grading script

Enter the JavaScript code that defines an array of your question field names and an array of correct answers. Use a for-loop to iterate through the fields, checking 'if (questionField.value != correctAnswers[i])' and setting 'questionField.textColor = color.red' if incorrect.

Use JavaScript to Evaluate Answers and Change Text Color
Script Accuracy: Make sure the field names in your JavaScript array match exactly with the names of the text fields created in your PDF document.
Create Interactive PDFs with WPS Office

Design and Edit PDF Forms Seamlessly with WPS Office

WPS PDF Editor provides comprehensive tools for creating interactive PDF forms. Whether you need text fields, buttons, or custom actions, WPS makes designing self-grading assessments straightforward and efficient.

  1. 1. Open your PDF: Launch WPS Office and select the 'PDF' tab to open your assessment document.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view all interactive form elements.
  3. 3. Add Fields and Buttons: Use the 'Text Field' and 'Button' tools to lay out your assessment structure.
  4. 4. Configure Properties: Double-click the newly created form fields to access properties, set up names, and apply your custom validation scripts.
Create and edit interactive PDF forms with easeCompatible with standard PDF form JavaScript actionsLightweight, fast, and user-friendly interfaceFree alternative with full Microsoft Office format compatibility
microsoft office alternative - wps office

Frequently Asked Questions

Can I change the background color of a PDF form field instead of the text color?

Yes, in your JavaScript, instead of targeting the 'textColor' property, you can target the 'fillColor' property (e.g., questionField.fillColor = color.red;) to highlight the background of the entire field.

Why isn't my JavaScript running when I click the PDF button?

Ensure that JavaScript is enabled in your PDF viewer's preferences. Additionally, check that the script is attached to the correct trigger event, typically 'Mouse Up', and verify that there are no syntax errors in your code.

How do I reset the form fields for a new student attempt?

You can add a separate 'Reset' button to your PDF document. In the button properties under the Actions tab, select 'Reset a form' to clear all text field inputs automatically.

Are there alternative tools for creating complex self-graded assessments?

For highly complex interactive assessments that require advanced grading logic, multimedia integrations, or LMS tracking, dedicated e-learning authoring tools like Adobe Captivate are often more suitable than standard PDF forms.