PDF Editing Issues

How to Validate Checkboxes and Lock PDF Form Fields Using Acrobat JavaScript

Chanuka GeekiyanageChanuka Geekiyanage Nov 5, 2026 869 views

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.

How to Validate Checkboxes and Lock PDF Form Fields Using Acrobat JavaScript
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.
Before you start

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.

Solution 1Recommended

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.

1
Loop to count active checkboxes

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.

2
Add validation alert

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.

3
Lock all form fields

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'.

4
Trigger the email function

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.

Implement JavaScript for Validation, Locking, and Emailing
Syntax Check: Always double-check your syntax. Ensure you are using '==' for comparisons and verify the script is assigned to trigger on the appropriate button action, such as 'Mouse Up'.
Efficient PDF Form Management

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. 1. Open your PDF form: Launch WPS Office and open your interactive PDF document containing the checkboxes and text fields.
  2. 2. Fill out the fields: Click directly on the checkboxes and text fields to fill out the necessary information securely.
  3. 3. Save the completed document: Go to the 'Menu' and click 'Save As' to create a finalized version of your filled document.
  4. 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.
Easily navigate and fill out interactive PDF form fieldsHighly compatible with standard interactive PDFs and Adobe formsLightweight, user-friendly interface for seamless document managementBuilt-in tools for instantly sharing and emailing finalized PDFs
microsoft office alternative - wps office

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.