How to Use Acrobat JavaScript to Open PDFs Based on Checkboxes
Question details
The user needs to configure a PDF form's Submit button to open specific saved PDF packets depending on which checkboxes are selected.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Writing JavaScript for a PDF form to evaluate multiple checkbox conditions and open the corresponding external PDF files upon submission.
- Observed behavior
- The current script works for a single checkbox condition but throws errors when multiple conditions are added due to incorrect operators and invalid commands like fopen.
Ensure you have access to the source PDF form in an editor that supports JavaScript editing, and verify the exact file paths of the destination PDF packets you want to open.
Correct JavaScript Syntax for Multiple Checkbox Conditions
Fix syntax errors by utilizing the standard JavaScript OR operator and replacing invalid functions with the correct Acrobat JavaScript API method.
When adding multiple conditions to a PDF form's Submit button, standard JavaScript logic must be paired with Acrobat-specific API methods. Errors typically occur from using invalid conditional operators or attempting to use standard programming functions like `fopen`, which are not supported in the Acrobat JavaScript API.
Right-click the Submit button in your PDF form, select Properties, navigate to the Actions tab, and choose to edit the 'Run a JavaScript' action.
To trigger an action when any one of multiple checkboxes is selected, replace any incorrect operators with the standard JavaScript logical OR operator (`||`) to chain your conditions together.
Remove any instances of `fopen` from your script. Use the Acrobat JavaScript command `app.openDoc()` to open external PDF files.
Ensure the path passed to the command is valid and correctly formatted. For example: `app.openDoc("/S/shz_online_agreements/site_files/packets/066p_PAF.pdf");`.

Create and Edit Interactive PDF Forms with WPS Office
WPS Office features a robust built-in PDF editor that allows you to easily create interactive forms, add checkboxes, and manage document structures without needing complex coding skills.
- 1. Open your PDF in WPS: Launch WPS Office and open your PDF document using the built-in WPS PDF editor.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive form controls suite.
- 3. Insert Controls: Click on 'Checkbox', 'Text Field', or 'Push Button' to insert them into your document. Double-click any control to easily configure its properties and actions.

Frequently Asked Questions
Why isn't my JavaScript opening the external PDF file?
If the PDF isn't opening, ensure you are using `app.openDoc()` instead of standard functions like `fopen`. Additionally, verify that the file path is correct and that your PDF viewer's security settings permit executing JavaScript and opening external files.
How do I check if multiple checkboxes are selected in PDF JavaScript?
You can check multiple checkboxes by accessing their values using `this.getField("CheckboxName").value`. Combine these field checks using the logical AND (`&&`) or logical OR (`||`) operators depending on the specific logic your form requires.
Does WPS Office support PDF form creation?
Yes, WPS Office includes comprehensive PDF editing features that allow you to create fillable forms. You can easily add checkboxes, text fields, drop-down menus, and buttons to collect data interactively.




