Use Buttons to Check Sequential PDF Form Boxes in Adobe Acrobat
Question details
Set up PDF form buttons to check or uncheck 20 sequential boxes and update a counter.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A form uses plus and minus buttons to control a sequence of checkboxes and display the number selected.
- Observed behavior
- The plus button should select the next box, and the minus button should clear the last selected box while the counter reflects the selection.
Open the PDF in Adobe Acrobat Pro and use Prepare a form to verify that the checkboxes are named Damage 1 through Damage 20 and the text field is named counter. Start with all boxes unchecked and the counter set to 0, or make sure the checked boxes form a sequence from Damage 1 and the counter matches their count.
Add JavaScript actions to the PDF form buttons
Use Acrobat button actions to select the first unchecked box or clear the last checked box, then recalculate the counter.
Each checkbox must have its own field name and a checked export value other than Off. Use the buttons to maintain the sequence; manually checking boxes out of order can leave gaps.
The scripts recount the checked boxes after each click, including when all boxes are already checked or unchecked.
In Adobe Acrobat Pro, open the PDF and choose All tools > Prepare a form. Confirm the checkbox names and counter field name in the field list, and check each box's export value in its Properties.
Open the plus button's Properties, select Actions, choose Mouse Up and Run a JavaScript, then click Add. Enter: for (var i = 1; i <= 20; i++) { var box = this.getField("Damage " + i); if (box.valueAsString == "Off") { box.checkThisBox(0, true); break; } } var count = 0; for (var j = 1; j <= 20; j++) { if (this.getField("Damage " + j).valueAsString != "Off") count++; } this.getField("counter").value = count;
Open the minus button's Properties and choose Actions > Mouse Up > Run a JavaScript > Add. Enter: for (var i = 20; i >= 1; i--) { var box = this.getField("Damage " + i); if (box.valueAsString != "Off") { box.checkThisBox(0, false); break; } } var count = 0; for (var j = 1; j <= 20; j++) { if (this.getField("Damage " + j).valueAsString != "Off") count++; } this.getField("counter").value = count;
Close the form editor, save the PDF, and click the plus and minus buttons. Check that the counter follows the boxes and remains at 0 or 20 when no further change is possible.

Work with Office documents and PDFs in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with Office documents and PDFs. It supports common Microsoft Office formats for an easier move between suites. Use Acrobat to author and test the JavaScript button actions described above.

Frequently Asked Questions
What happens when all 20 boxes are checked?
The plus script finds no unchecked box, so it leaves the selection unchanged and recalculates the counter as 20. Likewise, the minus script leaves an empty selection at 0.
Why does the counter not match the checked boxes?
In Acrobat's Prepare a form tool, verify that the text field is named counter and that all 20 checkbox names match the scripts. The scripts recalculate the total when either button is clicked.
Can I use different checkbox names?
Yes. In both button scripts, replace "Damage " with the prefix used by your fields. The scripts expect the names to end in consecutive numbers from 1 through 20.
Why don't the buttons work in my browser?
Some browser PDF viewers do not support Acrobat JavaScript. Open the saved form in Acrobat or Acrobat Reader and check the application's JavaScript preferences if the actions still do not run.




