PDF Editing Issues

How to Spawn PDF Page Templates Using Dropdown Export Values via JavaScript

Algirdas JasaitisAlgirdas Jasaitis Nov 5, 2026 869 views

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.

How to Spawn PDF Page Templates Using Dropdown Export Values via JavaScript
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.
Before you start

Ensure your PDF editor supports JavaScript for forms and that you have already created and named the hidden page templates you intend to spawn.

Solution 1Recommended

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.

1
Access Dropdown Properties

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.

2
Enter the Custom Keystroke Script

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; } }`.

3
Standardize the Export Values

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 Custom Keystroke Script for Dropdown Export Values
Script Event Timing: Using the keystroke event rather than a calculate event ensures the script fires instantly when the user makes a selection, preventing duplicate spawns during unrelated form calculations.
Robust PDF Form Solution

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. 1. Open PDF in WPS Office: Launch the WPS Office application and open the PDF document you want to make interactive.
  2. 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. 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.
Effortlessly insert dropdowns, checkboxes, and text fields into PDFs.High format compatibility with standard interactive PDF documents.User-friendly properties menu to define list items and export values quickly.Lightweight application that smoothly handles large and complex PDF forms.
microsoft office alternative - wps office

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()`.