Fix a PDF Form Field Counter and Position with Acrobat JavaScript
Question details
The user needs Up and Down buttons to move a PDF text field through five positions using a counter.

- Product
- PDF forms with Acrobat JavaScript
- Device & OS
- not provided
- Scenario
- A PDF form uses button scripts to change a counter and reposition a text field.
- Observed behavior
- The counter changes only once, and the text field may not move as intended.
Open the form in Adobe Acrobat and check the exact text field name in Prepare a Form. Identify five valid positions on the field's page; Acrobat field rectangles use points in the order left, top, right, bottom.
Correct the counter and assign a valid rectangle
Use a shared counter and a document-level function so both buttons can move the same field through five positions.
Use === for a comparison, such as counter === 1. A single = assigns a value instead of testing it, and counter.value is incorrect when counter is already a number.
The example below uses positions 0 through 4 and stops at either end. Replace the sample rectangles with coordinates that fit the field's page.
In Acrobat, open All tools > Prepare a form and select the text field. Check its name in Properties and use that exact name in place of Text1 in the script.
Open All tools > Use JavaScript > Document JavaScripts, add a script, and enter: var counter = 0; var positions = [[72,700,172,680],[72,670,172,650],[72,640,172,620],[72,610,172,590],[72,580,172,560]]; function moveField(direction) { var field = this.getField('Text1'); if (!field) return; counter = Math.max(0, Math.min(4, counter + direction)); field.rect = positions[counter]; }
In Prepare a form, open the Up button's Properties > Actions, choose Mouse Up and Run a JavaScript, and enter this.moveField(-1);. Set the Down button's Mouse Up action to this.moveField(1);.
Place the field at the first rectangle, save the PDF, and exit form editing. Click Down repeatedly, then Up, to check each position and confirm that movement stops at the ends.

Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Its format compatibility makes moving everyday files straightforward, but it does not replace Acrobat JavaScript troubleshooting.

Frequently Asked Questions
Why does my counter stop changing after one click?
Check each if condition for a single =, which assigns a value. Use a comparison such as counter === 1, and update the counter before selecting the field's new position.
Should I use counter.value in the condition?
No. If counter is a numeric JavaScript variable, compare counter directly. The value property is used for a form field object, not a number.
How do I specify a PDF form field's position?
Assign a valid four-number array to the field's rect property, for example field.rect = [72, 700, 172, 680]. The values represent left, top, right, and bottom in points; choose coordinates that fit the field's page.
Why do the buttons work in Acrobat but not in my browser?
Browser PDF viewers may not support Acrobat JavaScript or scripted form actions. Open the PDF in Acrobat and check that JavaScript is enabled in its preferences.




