How to Validate Checkboxes and Lock PDF Form Fields Using Acrobat JavaScript
Question details
The user needs to write an Acrobat JavaScript routine to validate that at least one checkbox is selected, make all form fields read-only after successful validation, and then email the completed PDF document.

- Product
- Adobe Acrobat PDF
- Device & OS
- not provided
- Scenario
- Developing an interactive PDF form that requires specific user input validation before locking the fields and automatically launching the email client for submission.
- Observed behavior
- The user is attempting to structure a script to count active checkboxes, apply the read-only property to every field systematically, and trigger the mailDoc command without syntax errors.
Ensure you have access to a PDF editor with JavaScript console support and always create a backup copy of your original PDF form before testing new scripts.
Implement JavaScript for Validation, Locking, and Emailing
Use a custom JavaScript loop to verify checkbox selections, lock all form fields properly, and trigger the email action only when conditions are met.
When writing Acrobat JavaScript, it is crucial to iterate through all form fields correctly. Use the equality operator '==' for evaluating conditions instead of the assignment operator '='.
Additionally, ensure the 'readonly' property is applied to every individual field inside a loop, rather than accidentally targeting only the last accessed field.
Write a 'for' loop to iterate through the document's fields. Check if the field type is a checkbox and ensure its value is not equal to 'Off' (which indicates it is selected). Increment a counter for each selected checkbox.
Use an 'if' statement to verify the checkbox count. If the count is zero, display an alert via 'app.alert()' prompting the user to select at least one required checkbox, and then abort the submission.
If the validation passes, create a second 'for' loop to go through all the fields in the document and set their state to read-only by assigning 'field.readonly = true'.
Finally, after the fields are successfully locked, call the 'this.mailDoc()' function. This will open the user's default email client and automatically attach the locked, completed PDF form.

Manage Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive PDF toolkit that allows you to easily open, fill, and manage interactive form fields, ensuring seamless document processing and sharing.
- 1. Open your PDF form: Launch WPS Office and open your interactive PDF document containing the checkboxes and text fields.
- 2. Fill out the fields: Click directly on the checkboxes and text fields to fill out the necessary information securely.
- 3. Save the completed document: Go to the 'Menu' and click 'Save As' to create a finalized version of your filled document.
- 4. Share via email: Click the 'Share' or 'Email' button on the top toolbar to automatically attach the completed PDF to a new email draft.

Frequently Asked Questions
Why is my Acrobat JavaScript not setting all fields to read-only?
This usually happens if the script applies the readonly property only to the last evaluated field instead of iterating through all fields. Ensure you are using a loop to systematically apply 'field.readonly = true' to every field in the document.
How do I check if a PDF checkbox is selected using JavaScript?
You can determine a checkbox's state by evaluating its value. In Acrobat JavaScript, if the value is equal to 'Off', the checkbox is unselected. Any other export value indicates that it is actively selected.
Can I send an email directly from a PDF form button?
Yes, you can assign a JavaScript action to a PDF button that calls the 'this.mailDoc()' function. This command will launch the user's default email application with the current PDF document attached.




