On this Page

    _page (The Page DOM)

    _page is a JavaScript object which represents the DOM for a given Page object. This object is created dynamically and automatically for the page on which the object using _page exists. _page is undefined for the Form object as a Form is not on a page. If you choose to use the _page object it must be on a Page object or somewhere in a page's descendant tree of objects. The _page object does not refer to all pages in the document. Rather, it refers to only those instances of pages on which the object referring to _page resides. For example, if the object whose script references _page is, say the "Amount" Field, and that Field is on a Page named "LayoutTwo", then that _page reference will be to only the various instances of the Page named "LayoutTwo". As usual, _page[0] would refer to the first such instance and _page[1] would refer to the second such instance, etc.

    To refer to all the pages in a document, you do not use the _page object. The following script excerpt shows one way to refer to all the pages in a document. By looking in the Form Explorer panel you can see that all Pages are the immediate children of the Form object. Hence, when wanting to refer to all the pages in a document you are wanting to refer to all the immediate children of the Form object.

     for (var r = _document._firstChild; r; r = r._nextSibling) {
         _logf("Page '%s'\n", r._fullName);
         // ... do your desired page processing
     }

    When working at the Page level it is good to remember that every object (except the Form object) has a _pageNumber property. Of course, that is valid only on or after the Pagination Completed event. There is also an _auto.PageNumber property but its usage is discouraged. Clearly, it does not provide the page number of the _auto object -- that would be nonsensical. Rather, it provides the page number of the current global object, the this object, i.e. the object in which the _auto.PageNumber reference is made. If you want to know the page number of something then use the _pageNumber property reference on that something object.

    Also, consider _auto.PageCount as a means to know how many pages exist in the document.

    Notice the unusual property naming -- no leading underscore. That is because _auto is a "synthesized" object, not a user object on the form, and hence no collision can occur with the property name PageCount. As it happens, in another atypical way, PageCount is a case-insensitive property name of the _auto object. _auto.PC is a valid synonym.

    Somewhat curiously, you can also use this._pageCount or this._numberOfPages. It seems that everywhere you look you can find the number of pages in the document.