Fix Acrobat Form Button Not Working After Spawning a Page
Question details
The user needs to fix a PDF form button that uses JavaScript to insert the date and time but stops working after a new page is spawned.

- Product
- Adobe Acrobat / PDF Forms
- Device & OS
- not provided
- Scenario
- Using JavaScript buttons on a PDF form that dynamically spawns new template pages.
- Observed behavior
- After spawning a page, Acrobat automatically alters field names by appending the page hierarchy, causing the original script to fail because it cannot find the statically referenced fields.
Before editing your form scripts, ensure you have a backup of the original PDF file. Be aware that advanced JavaScript and page template spawning are generally only fully supported on desktop PDF viewers, so ensure you are testing on a desktop application.
Update JavaScript to Resolve Relative Field Names
Modify your script so it dynamically captures the updated field names based on the newly spawned page hierarchy.
When Adobe Acrobat spawns a page from a template, it renames the fields to prevent data duplication across pages. For example, a field originally named 'DateofRequest' might become 'P1.TemplateName.DateofRequest'. To fix the broken button, the script must be updated to reference these new, hierarchical field names.
Open your PDF form in Adobe Acrobat, right-click the button that inserts the date and time, and select 'Properties'. Go to the 'Actions' tab and edit the 'Run a JavaScript' action.
Change the static getField() call to account for the spawned hierarchy. For instance, reference the spawned field explicitly like getField("P1.BD.BF_DateofRequest") if the prefix is known.
Alternatively, write a script that dynamically extracts the current page's prefix from the event target name, and concatenates it with the base field name so the button works regardless of how many pages are spawned.
Save your changes and test the button inside the desktop version of Adobe Acrobat or Reader to ensure the JavaScript executes properly.

Use WPS PDF to Fill and Manage Interactive Forms
WPS Office includes a powerful PDF editor that supports interactive form filling, JavaScript execution, and comprehensive document management. You can easily manage form fields without running into complex template spawning errors.
- 1. Open your PDF in WPS Office: Launch WPS Office, click on 'Open', and select your interactive PDF form.
- 2. Navigate to the Form Tab: Click on the 'Form' tab in the top ribbon to access all interactive field controls.
- 3. Edit or Fill Fields: Click directly on the text fields, date pickers, or buttons to interact with the form and trigger standard scripts.
- 4. Save and Share: Once filled, click 'Save' to retain all your inputted data, or use 'Export to PDF' to flatten the fields before sharing.

Frequently Asked Questions
Why do PDF form fields get renamed when spawning a template page?
PDF software renames fields by adding a hierarchical prefix (like 'P1.TemplateName') to ensure each field on the newly spawned page has a unique identifier. This prevents data entered on one page from accidentally duplicating onto another page that uses the same original field name.
Can I use JavaScript to dynamically find spawned PDF fields?
Yes. You can write JavaScript to extract the prefix of the button being clicked (using its name or target) and use that prefix to locate other fields on the same spawned page using the getField() method.
Why doesn't my PDF form's JavaScript work on mobile devices?
Most mobile PDF viewer apps lack the full JavaScript engine found in desktop applications. Complex actions like template spawning, relative field tracking, and advanced calculations typically require a desktop environment to function.
How do I insert a date automatically in a PDF form without scripting?
If you want to avoid JavaScript entirely, you can use standard form editing tools in software like WPS PDF to insert a date field manually or use a predefined date picker, though it will not automatically populate the current time on a single button click without a script.




