Fix Checkbox JavaScript on Spawned PDF Pages in Adobe Acrobat
Question details
Make a checkbox script identify related fields on both the original PDF form page and pages spawned from a template.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF template creates additional form pages whose field names have page and template prefixes.
- Observed behavior
- The checkbox script works on the original page but does not find the related image and text fields on spawned pages.
Open the PDF in Adobe Acrobat and use Prepare a Form to inspect the checkbox and related field names on both the original and spawned pages. Confirm that spawned names follow a pattern such as P2.Template.FieldName.
Extract the spawned-page prefix from the checkbox field name
Use the triggering checkbox name to locate related fields on the same spawned page while retaining support for unprefixed original fields.
The example assumes spawned fields have two prefix components, such as P2.Template, followed by the original field name. If your field names use a different structure, adjust the prefix extraction to match.
In Acrobat, open Prepare a Form, right-click the checkbox on the template, and select Properties. On the Actions tab, select the Mouse Up trigger and add or edit a Run a JavaScript action.
In the JavaScript editor, adapt the visibility logic to use the prefix from event.target.name. For example: var parts = event.target.name.split('.'); var prefix = parts.length > 2 ? parts[0] + '.' + parts[1] + '.' : ''; var imageField = this.getField(prefix + 'Image15_af_image'); var textField = this.getField(prefix + 'AskDetails15'); var show = event.target.value !== 'Off'; if (imageField) imageField.display = show ? display.visible : display.hidden; if (textField) textField.display = show ? display.visible : display.hidden;
Save the action, exit Prepare a Form, and toggle the checkbox on the original page and a newly spawned page. Confirm that each checkbox changes the image and text fields on its own page.

Work with PDF and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDF and Office files. Its format compatibility helps you bring existing documents into your workflow, but it does not fix Acrobat's spawned-field JavaScript.

Frequently Asked Questions
Why does the script work on the original page but not the spawned page?
Acrobat can add a page and template prefix to spawned field names. A lookup such as this.getField('AskDetails15') will not find a field named P2.Template.AskDetails15 unless the prefix is included.
Where can I find the checkbox's JavaScript in Acrobat?
Open Prepare a Form, right-click the checkbox, and select Properties. On the Actions tab, look for a Run a JavaScript action under the relevant trigger, such as Mouse Up.
What happens if a related field name is incorrect?
this.getField() returns null when it cannot find the field. Check the full name in Prepare a Form and confirm that the script combines the correct prefix and unprefixed field name.
Will the example work if my field names contain additional periods?
Not necessarily. The example treats the first two components as the spawned-page prefix when there are more than two components. Inspect your original and spawned names and adjust the extraction logic if they use a different pattern.




