PDF Editing Issues

Use Acrobat Buttons to Fill Sequential PDF Form Fields

Kushani NimanthikaKushani Nimanthika Nov 19, 2026 868 views

Question details

Set up Heads and Tails buttons that record values in sequential PDF form fields without overwriting earlier entries.

Use Acrobat Buttons to Fill Sequential PDF Form Fields
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF form has sequential toss fields and two buttons for recording Heads or Tails.
Observed behavior
Each button should fill the first empty field with its assigned value and display an alert when all fields are full.
Before you start

Open the PDF in Adobe Acrobat and check that it has text fields named toss1 through toss5, plus Heads and Tails buttons. Make sure the fields start empty and Acrobat JavaScript is enabled in Preferences.

Solution 1Recommended

Add a Mouse Up JavaScript action to each Acrobat button

Use a script to find the first empty toss field, record the selected result, and stop when all five fields are filled.

1
Open the form editor

In Acrobat, open the PDF and choose Prepare a Form from the tools menu. Create or rename the text fields toss1 through toss5 and add Heads and Tails buttons if needed.

2
Configure the Heads button

Open the Heads button's Properties and select the Actions tab. Set Select Trigger to Mouse Up and Select Action to Run a JavaScript, then click Add.

3
Enter the Heads script

In the JavaScript editor, enter the following and click OK: for (var i = 1; i <= 5; i++) { if (this.getField("toss" + i).valueAsString === "") { this.getField("toss" + i).value = "1"; break; } } if (i > 5) app.alert("You cannot perform another toss.", 1);

4
Configure the Tails button

Open the Tails button's Properties and add a Mouse Up action using Run a JavaScript. Paste the same script, but change the assigned value from "1" to "0".

5
Save and test the form

Save the PDF, exit Prepare a Form, and click Heads and Tails in different sequences. Confirm that each click fills the next empty field, earlier entries remain unchanged, and a sixth click displays the alert.

Add a Mouse Up JavaScript action to each Acrobat button
Keep unused fields blank: Use a nonblank value for every recorded result so the script can distinguish it from an unused field. If you use a different number of fields, update both occurrences of 5 in each script. On Windows, press Ctrl+J in Acrobat to check the JavaScript Console for errors.
Free Microsoft Office alternative

Work with PDF Forms and Office Files in WPS Office

WPS Office is a free, lightweight, easy-to-use alternative for everyday PDF and Office work. Its familiar interface and format compatibility make it easier to move between existing files; use Acrobat to create and test the button scripts described above.

Open and work with PDF documents alongside your office filesCompatible with Microsoft Office formats including DOCX, XLSX, and PPTXFamiliar interface supports a smoother move from Microsoft OfficeFree and lightweight for everyday document tasks
microsoft office alternative - wps office

Frequently Asked Questions

Why does the script use the first empty field?

The Mouse Up script checks toss1 through toss5 in order and writes to the first field whose valueAsString is empty. The break statement stops it from changing later fields.

How do I add more than five toss fields?

In Prepare a Form, add fields with consecutive names such as toss6 and toss7. In each button's script, change both occurrences of 5 to the new total.

What happens when every toss field is filled?

The loop finds no empty field, so the script displays “You cannot perform another toss.” No existing entry is changed.

Why isn't my button script working?

In Acrobat, check the button's Properties > Actions tab for a Mouse Up trigger and Run a JavaScript action. Verify the field names and JavaScript preference; on Windows, press Ctrl+J to inspect the JavaScript Console.

Can I use a blank value for one of the results?

No. The script treats a blank field as unused, so a blank result could be overwritten. Assign a nonblank value such as 0, 1, or a dash instead.