Fix Acrobat JavaScript Syntax Errors When Combining Checkbox Values
Question details
The user needs to resolve an illegal-character syntax error in a custom calculation script designed to collect export values from multiple checkboxes into one text field.

- Product
- Adobe Acrobat Pro 2017
- Device & OS
- not provided
- Scenario
- Writing a custom JavaScript in a PDF document to dynamically combine the export values of 25 checkboxes.
- Observed behavior
- The PDF editor reports an illegal-character syntax error, preventing the script from running and populating the text field as intended.
Ensure you have access to the PDF form in editing mode and open the JavaScript console (Ctrl+J on Windows or Cmd+J on Mac) to view exact error messages.
Use a Plain Text Editor to Remove Hidden Formatting
Strips invisible characters and smart quotes that are often introduced when copying code from a word processor.
Editing scripts in word processors like Microsoft Word can introduce invisible rich-text formatting, smart quotes (curly quotes), or bold characters. JavaScript requires pure ASCII text, so these hidden elements will trigger illegal-character syntax errors.
Highlight and copy the problematic JavaScript code from your PDF or word processor.
Launch Notepad on Windows or TextEdit on Mac (ensure it is set to 'Make Plain Text' in the Format menu).
Paste your code into the plain text editor to strip all formatting, then copy the plain text back to your clipboard.
Paste the clean ASCII text directly into the Acrobat JavaScript editor and save your changes.

Validate Field Names and Null Checks
Ensures the script properly locates every checkbox and does not crash if a field is missing or incorrectly named.
Create and Manage Interactive PDF Forms with WPS Office
WPS Office features a robust built-in PDF editor that allows you to easily insert checkboxes, text fields, and interactive form controls without relying on complex custom JavaScript for basic form setups.
- 1. Open your PDF: Launch WPS Office and open your PDF document.
- 2. Access form tools: Navigate to the 'Form' tab on the top ribbon menu to access the interactive elements.
- 3. Add checkboxes: Click 'Check Box' and click on the document area where you want to place the interactive toggle.
- 4. Adjust properties: Double-click the inserted field to open the properties panel, where you can easily set export values and display names.
- 5. Save the interactive form: Save your document to preserve the interactive fields, ensuring seamless compatibility across standard PDF readers.

Frequently Asked Questions
Why does my PDF JavaScript report an illegal character error?
This usually occurs when the script was pasted from a word processor that uses smart quotes (curly quotes) or hidden rich-text formatting instead of standard ASCII plain text. Always use a plain text editor for scripts.
Do I need a self-executing function for PDF JavaScript calculations?
No, a self-executing function is generally unnecessary for basic PDF form calculation scripts. Standard variable declarations and loops will execute properly directly in the calculation script window.
How do I correctly read the value of a checkbox in PDF JavaScript?
You can retrieve it using the `getField("FieldName").valueAsString` method. Keep in mind that if the checkbox is unchecked, its default string value is usually 'Off'.




