How to Use JavaScript to Spawn a PDF Form and Increment a Number
Question details
The user wants to use JavaScript to spawn a two-page PDF form and dynamically increase a ticket number field by one upon form submission.

- Product
- Adobe Acrobat / PDF Forms
- Device & OS
- not provided
- Scenario
- Creating an interactive ticketing or invoicing PDF form that generates new pages and automatically updates the sequence number.
- Observed behavior
- The user needs the specific scripting logic or method to identify newly created fields on spawned pages so they can be populated with the correct incremented ticket number.
Ensure you have access to a fully-featured PDF editor with JavaScript capabilities and that your base PDF form has properly defined template names before writing your script.
Identify and Populate Dynamically Spawned PDF Fields
Calculate the predictable field names on newly spawned PDF pages to successfully insert incremented values.
When you spawn pages from a template in a PDF, the fields on those new pages do not keep their original names. Instead, they are renamed dynamically to avoid conflicts. To interact with these new fields, your JavaScript must determine their generated names.
Use the Acrobat JavaScript 'spawn' method in your form submission action to create the new two-page set from your existing hidden template.
Construct the new field names in your script. The predictable naming convention usually combines the template name, the new page number, and the original field name.
Retrieve the current ticket number from the active field, parse it as an integer, and increment its value by one.
Target the newly constructed field names using the 'getField' method and assign the newly incremented ticket number to their value properties.

Manage and Fill PDF Forms Easily with WPS Office
While advanced JavaScript template spawning requires complex coding, WPS Office provides a comprehensive PDF toolset that allows you to easily view, fill out, and manage standard interactive PDF forms without the hassle.
- 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and launch the application.
- 2. Open Your PDF Document: Launch WPS PDF and open your interactive PDF form or document.
- 3. Interact with Form Fields: Click directly on the text fields, checkboxes, or dropdown menus to fill in your data.
- 4. Save and Export: Save the modified PDF directly or export it to share with clients or colleagues.

Frequently Asked Questions
Why aren't my spawned PDF fields updating automatically?
Spawned fields inherit entirely new names based on the template and page number. Your script must explicitly target these dynamically generated field names to update their values.
What is the naming convention for spawned fields in Acrobat?
Typically, spawned fields are named using a combination of the template name, the page number index, and the original field name, separated by periods.
Can I automatically increment numbers in a PDF without using JavaScript?
No, standard PDF forms do not support automatic incrementing logic (like ticket numbers or invoice sequences) without utilizing custom JavaScript tied to a button, calculation, or submission action.
Do I need special software to add JavaScript to my PDF forms?
Yes, adding and editing custom document-level or field-level JavaScript logic generally requires a fully-featured PDF editor such as Adobe Acrobat Pro.




