Calculate Checkbox Values and Change Field Colors in Adobe Acrobat Forms
Question details
Create an Acrobat form where checkbox selections determine another field's value and background color, and a separate field totals selected values.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form needs to calculate a value and display a color based on checkbox selections.
- Observed behavior
- Selecting a checkbox should set a calculated field's value and fill color; another field should sum the required fields.
Open the PDF in a version of Adobe Acrobat that supports editing forms, and make sure the checkboxes and calculated fields have unique names. This example uses checkboxes A, B, and C, a calculated text field D, and a total field E.
Add a custom calculation script to the Acrobat form
Use this method to set field D's value and background color from three checkboxes, then configure field E to calculate a total.
The script checks A first, then B, then C. If more than one checkbox is selected, the first checked field in that order determines the result.
Open the PDF in Adobe Acrobat and select All tools > Prepare a form. Create or identify checkboxes A, B, and C and text fields D and E.
In Prepare a form, open field D's Properties, select the Calculate tab, choose Custom calculation script, and select Edit. Enter: if (this.getField("A").valueAsString != "Off") { event.value = 10; event.target.fillColor = color.red; } else if (this.getField("B").valueAsString != "Off") { event.value = 25; event.target.fillColor = color.yellow; } else if (this.getField("C").valueAsString != "Off") { event.value = 50; event.target.fillColor = color.green; } else { event.value = ""; event.target.fillColor = color.transparent; }
In the script editor, replace A, B, and C with the exact names of your checkbox fields if they differ. Save the script and close field D's Properties.
Open field E's Properties and select Calculate. Choose Value is the and select Sum, then use Pick to select D and any other fields to include. Do not include E itself.
Preview the form in Acrobat and select and clear each checkbox. Confirm that D displays the expected value and color and that E updates its total. Save the PDF.

Manage Related Form Data in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface and Microsoft Office format compatibility for moving related documents and spreadsheets. It does not replace Adobe Acrobat for creating or running the custom PDF form script described above.

Frequently Asked Questions
What happens if more than one checkbox is selected?
The script uses the first selected checkbox in its order: A, then B, then C. If only one choice should be allowed, consider using a radio button group instead.
How do I change the values or colors?
In Acrobat's Prepare a form tool, open field D's Properties > Calculate and edit the custom calculation script. Change the numbers assigned to event.value or the colors assigned to event.target.fillColor.
Why is the total field not updating correctly?
In field E's Properties > Calculate, check that Sum includes the intended fields and excludes E. Also check the field calculation order so that D is calculated before E.
Will the calculation work in every PDF viewer?
Not necessarily. The custom calculation and color changes require a viewer that supports Acrobat form JavaScript. Test the saved PDF in the viewer your recipients will use.




