PDF Editing Issues

Fix Acrobat JavaScript Syntax Errors When Combining Checkbox Values

Kushani NimanthikaKushani Nimanthika Nov 3, 2026 868 views

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.

Fix Acrobat JavaScript Syntax Errors When Combining Checkbox Values
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.
Before you start

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.

Solution 1Recommended

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.

1
Copy the original script

Highlight and copy the problematic JavaScript code from your PDF or word processor.

2
Open a plain text editor

Launch Notepad on Windows or TextEdit on Mac (ensure it is set to 'Make Plain Text' in the Format menu).

3
Paste and recopy

Paste your code into the plain text editor to strip all formatting, then copy the plain text back to your clipboard.

4
Update the PDF script

Paste the clean ASCII text directly into the Acrobat JavaScript editor and save your changes.

Use a Plain Text Editor to Remove Hidden Formatting
Best Practice: Always type or edit JavaScript directly within the PDF application's script window or a dedicated code editor like VS Code.

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. 1. Open your PDF: Launch WPS Office and open your PDF document.
  2. 2. Access form tools: Navigate to the 'Form' tab on the top ribbon menu to access the interactive elements.
  3. 3. Add checkboxes: Click 'Check Box' and click on the document area where you want to place the interactive toggle.
  4. 4. Adjust properties: Double-click the inserted field to open the properties panel, where you can easily set export values and display names.
  5. 5. Save the interactive form: Save your document to preserve the interactive fields, ensuring seamless compatibility across standard PDF readers.
Easily insert, align, and manage PDF form fields like checkboxes and text boxes.Highly compatible with standard PDF forms and Adobe Acrobat formatting.Lightweight PDF editing built directly into the free WPS Office suite.
microsoft office alternative - wps office

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