How to Require Multiple Checkboxes Before PDF JavaScript Runs
Question details
The user wants to configure a PDF form so that a JavaScript action (such as populating a text field with a specific value) only triggers when two or more required checkboxes are selected.

- Product
- PDF Forms
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms with conditional logic to control when fields are populated based on user selections.
- Observed behavior
- The current script activates when a single checkbox is clicked, but the desired behavior is to evaluate the state of multiple checkboxes before outputting a result.
Ensure you have a PDF editor that supports form field creation and JavaScript execution. Note down the exact names of your checkboxes and the target text field, as JavaScript is case-sensitive.
Use a Custom Calculation Script on the Result Field
Apply a JavaScript calculation to the target text field that checks if the required checkboxes are selected before setting its value.
Instead of attaching the script directly to the checkboxes, handle this one-to-many relationship by adding a calculation script to the result field. This script will evaluate the state of all specified checkboxes whenever a change is made.
Open your document in your PDF editor and enter the Form Editing mode.
Right-click the target text field (the field where the value '1' should appear) and select 'Properties'.
Navigate to the 'Calculate' tab, choose 'Custom calculation script', and click 'Edit'.
Input the following script: if (this.getField("Check1").value !== "Off" && this.getField("Check2").value !== "Off") { event.value = "1"; } else { event.value = ""; } (Replace "Check1" and "Check2" with your actual checkbox field names).
Click 'OK' to save the script, close the properties window, and test the form to verify the text field populates only when both checkboxes are ticked.

Set Checkboxes as Required for Form Submission
If your goal is simply to ensure users check these boxes before submitting the form, you can mark them as required fields individually.
Create and Manage Advanced PDF Forms with WPS Office
WPS Office provides a comprehensive suite of PDF tools, allowing you to easily insert checkboxes, text fields, and apply custom JavaScript calculations to create interactive, professional forms.
- 1. Open PDF in WPS: Launch WPS Office and open your PDF document.
- 2. Access Form Tools: Navigate to the 'Form' tab to access tools for creating checkboxes and text fields.
- 3. Configure Properties: Double-click a form field to open its properties, where you can set it as required or add JavaScript actions.
- 4. Save and Test: Exit form editing mode to test your conditional logic and save the finalized document.

Frequently Asked Questions
Why isn't my PDF calculation script running immediately when checkboxes are clicked?
If the script only runs when you click away from the checkbox, you need to enable the 'Commit selected value immediately' setting. Right-click your checkbox, go to Properties > Options, and check this box so the value registers instantly.
How do I check if a checkbox is selected in PDF JavaScript?
You can check the value of the checkbox field. If it returns 'Off', it is unchecked. If it returns the export value (usually 'Yes' or 'On'), it is selected. For example: this.getField("Checkbox1").value !== "Off".
Can I require three or more checkboxes instead of two?
Yes, you can expand the script using the logical AND operator (&&). Just add another condition: && this.getField("Check3").value !== "Off" to your if statement.
What if I want the script to run if ANY of the checkboxes are selected?
If you want an 'OR' condition instead of an 'AND' condition, replace the && operators in your script with ||. This will cause the text field to populate if at least one of the listed checkboxes is selected.




