Spawn a Hidden PDF Template Based on Two Form Conditions in Adobe Acrobat
Question details
Spawn a hidden PDF page template only when a checkbox is selected and a text field contains an accepted value.

- Product
- Adobe Acrobat Pro
- Device & OS
- not provided
- Scenario
- A multipage PDF form needs to select and spawn a page template according to two form-field conditions.
- Observed behavior
- The form should check both conditions before running the template-spawning script.
In Acrobat Pro, identify the exact checkbox and text-field names and create a named hidden page template. Decide which text values should trigger each template and test the form in a PDF viewer that supports Acrobat JavaScript.
Validate the Text Field and Spawn the Matching PDF Template
Use a custom validation script when the text field is completed after the checkbox is selected.
The script checks that the checkbox is not Off and that the entered text matches one of the accepted values. It uses event.value for the text being validated.
This example spawns one template for the listed values. If other values require a different template, add a separate condition and use that template's name.
Open the PDF in Acrobat Pro, choose Prepare a Form, then right-click the relevant text field and select Properties.
On the Validate tab, select Run custom validation script and click Edit. Enter: var checkbox = this.getField("CHECKBOX"); var value = String(event.value).replace(/^\s+|\s+$/g, "").toUpperCase(); if (checkbox && checkbox.value !== "Off" && ["BC", "AB", "SK", "MB", "ON"].indexOf(value) !== -1) { var template = this.getTemplate("TemplateName"); if (template) { template.spawn({nPage: this.numPages, bRename: true, bOverlay: false}); } }
In the script editor, replace CHECKBOX with the exact checkbox field name and TemplateName with the hidden template name. Edit the array to match the accepted text values, then confirm the script and close Properties.
Preview the form, select the checkbox, enter an accepted value, and leave the text field to commit it. Repeat with an unchecked box and an unlisted value to confirm that neither case spawns a page.

Use WPS Office for Everyday PDF and Office Document Work
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office files. Its format compatibility makes it easy to move existing documents into WPS. For conditional Acrobat JavaScript template spawning, continue to use Acrobat and a compatible PDF viewer.

Frequently Asked Questions
Why should I use an array for the accepted text values?
An array lets the script test whether event.value matches any listed value using indexOf. An expression such as value == "BC" || "AB" does not compare value with each string and can evaluate as true unexpectedly.
What does the checkbox value Off mean?
In an Acrobat checkbox field, Off represents the unchecked state. The script checks checkbox.value !== "Off" so that a checked export value can satisfy the condition.
Why does changing the checkbox not spawn a page?
The example runs from the text field's Validate tab when that field is committed. If users may select the checkbox afterward, add a separate checkbox script that reevaluates both conditions.
Can the script spawn a different template for another text value?
Yes. Add another condition for the relevant value or group of values, then call this.getTemplate with the corresponding template name before invoking spawn.
Will this script work in every PDF viewer?
No. The viewer must support the necessary Acrobat JavaScript and template operations. Test the completed form in the intended viewer; Reader usage may also depend on document permissions and enabled features.




