PDF Editing Issues

Fix a PDF Form Field Counter and Position with Acrobat JavaScript

Bushra ParveenBushra Parveen Nov 24, 2026 868 views

Question details

The user needs Up and Down buttons to move a PDF text field through five positions using a counter.

Fix a PDF Form Field Counter and Position with Acrobat JavaScript
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.
Before you start

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.

Solution 1Recommended

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.

1
Check the field name

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.

2
Add a document-level 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]; }

3
Set the button actions

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);.

4
Test all five positions

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.

Correct the counter and assign a valid rectangle
Check viewer support: Test in Acrobat or another PDF viewer that supports Acrobat JavaScript. Browser PDF viewers may not run the scripts, and the counter resets when the document is reopened.
Free Microsoft Office alternative

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.

Open and review PDF documents alongside your office filesCompatible with Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXFamiliar tools help you transition from Microsoft OfficeFree and lightweight for everyday document work
microsoft office alternative - wps office

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.