How to Spawn PDF Page Templates Using Dropdown Export Values via JavaScript
Question details
The user needs to spawn specific PDF page templates dynamically based on the selected export value of a dropdown menu, rather than writing code for every individual dropdown choice.

- Product
- Adobe Acrobat PDF
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where a dropdown list with multiple items is grouped into two main categories, each triggering a different hidden page template to spawn.
- Observed behavior
- The current setup requires targeting individual item names. The user wants to intercept the non-committed export value ('Full' or 'Simplified') to trigger the spawn action cleanly.
Ensure your PDF editor supports JavaScript for forms and that you have already created and named the hidden page templates you intend to spawn.
Use Custom Keystroke Script for Dropdown Export Values
Trigger the template spawning by intercepting the dropdown's non-committed export value (`event.changeEx`) using a Custom Keystroke Script.
By checking the `event.willCommit` condition, the script can read the export value of the choice the user just clicked before the field fully commits the data.
This allows you to assign identical export values (e.g., 'Full' or 'Simplified') to multiple choices in the dropdown, keeping your JavaScript clean and highly scalable.
Right-click your dropdown field in form editing mode, select 'Properties', and navigate to the 'Format' or 'Keystroke' tab depending on your PDF editor's interface.
Select the option for a custom keystroke script and insert the following code: `if (!event.willCommit) { switch (event.changeEx) { case "Full": this.getTemplate("1 Ind CIP Long").spawn({bRename: false, bOverlay: true}); break; case "Simplified": this.getTemplate("1 Ind CIP Short").spawn({bRename: false, bOverlay: true}); break; } }`.
Navigate to the 'Options' tab of your dropdown properties. Ensure that every listed item corresponds exactly to the export values defined in your script (e.g., "Full" or "Simplified").

Use the Field Calculate Event (Alternative Method)
Move the logic to the calculation event if you need the template to spawn only after the entire form evaluates.
Easily Create and Manage Interactive PDF Forms with WPS Office
While advanced template spawning requires specialized JavaScript engines, WPS Office provides a highly intuitive PDF editor for designing forms, configuring dropdowns, and managing export values without needing to write complex code.
- 1. Open PDF in WPS Office: Launch the WPS Office application and open the PDF document you want to make interactive.
- 2. Access Form Controls: Navigate to the 'Form' tab on the top ribbon, where you can select tools like 'Combo Box' (Dropdown) or 'Text Field'.
- 3. Configure Dropdown Values: Double-click the inserted dropdown field to open its properties, then easily add item names and define their corresponding export values in the Options tab.

Frequently Asked Questions
What is the difference between `event.changeEx` and `event.value` in PDF JavaScript?
`event.changeEx` captures the export value of a newly selected dropdown item during the Keystroke event (before it commits). `event.value` represents the finalized value of the field after the user's selection has been fully committed.
Why use `event.willCommit` in a keystroke script?
It allows the script to evaluate or modify the input while the user is actively interacting with the field. By checking `if (!event.willCommit)`, you ensure the template spawns instantly as the dropdown selection changes.
Can I assign the same export value to multiple dropdown choices?
Yes, PDF forms allow multiple descriptive list items to share the same export value. This is highly useful for grouping numerous choices under a single category like 'Full' or 'Simplified' to minimize JavaScript conditions.
Why is my PDF page template not spawning?
Ensure the template name in your `.getTemplate("Name")` script exactly matches the hidden template's name in your document. Also, check that your PDF viewer fully supports advanced JavaScript execution, as some browser-based viewers do not support `.spawn()`.




