Get the First PDF Form Field Page with Acrobat JavaScript
Question details
Find and display the first page associated with a required PDF form field, including fields repeated on multiple pages.

- Product
- Adobe Acrobat PDF forms and JavaScript
- Device & OS
- not provided
- Scenario
- A form-validation script lists required fields and should show only one page number for each field.
- Observed behavior
- The field's page property can be a single zero-based page index or an array of indexes when the field appears on multiple pages.
Open the PDF in Adobe Acrobat and identify the form field or validation script you want to check. Acrobat JavaScript must be enabled to run the script.
Select the First Acrobat Form Field Page Index
Use this approach when a field's page property may be either a number or an array.
Open the PDF in Adobe Acrobat, then open the JavaScript console with Ctrl+J on Windows or Command+J on macOS.
In your validation script, use the first array element when needed: var pages = f.page; var pageIndex = pages instanceof Array ? pages[0] : pages;
After confirming pageIndex is a nonnegative number, add it to your message as "Page " + (pageIndex + 1). Acrobat uses zero-based page indexes, so adding 1 gives the page number a reader expects.
Run the updated script from the JavaScript console or the form's validation action. Test a field that appears on one page and a field that appears on several pages.

Work with PDF Files and Office Documents 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 easier, but it does not replace the Acrobat-specific JavaScript solution on this page.

Frequently Asked Questions
Why does f.page sometimes return an array?
In Acrobat JavaScript, a field that appears on multiple pages can return an array of zero-based page indexes. A field on one page can return a single index instead.
How do I show a reader-friendly page number?
Select the appropriate index from f.page, verify that it is nonnegative, and add 1 before displaying it. For example, index 0 is page 1.
Does f.page[0] always give the earliest page in the PDF?
It gives the first index in the returned array. If the array is not ordered by page and you need the lowest page index, filter out invalid indexes and select the minimum.
Does comparing a field's value with its default always find empty fields?
No. A field can have a nonempty default value, so the comparison finds values unchanged from their defaults. Adjust the validation condition for the field types and definition of empty in your form.




