Fix Illegal Character Syntax Errors in Acrobat PDF Form JavaScript
Question details
The user encounters a 'SyntaxError: illegal character' when running a custom calculation script in an Acrobat PDF form.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Writing or executing custom JavaScript calculation equations for specific PDF form fields.
- Observed behavior
- The script fails and throws a syntax error due to the use of the '#' symbol in variable declarations and improper syntax for the Math.min function.
Ensure you have editing permissions for the PDF form fields and open your document in the Acrobat form preparation mode to access the calculation properties.
Correct Variable Names and Math Function Syntax
Resolve the illegal character syntax error by updating JavaScript variable names to remove special symbols and properly formatting the math equations.
Acrobat PDF form calculations rely on standard JavaScript rules. Using invalid characters like '#' in variable declarations or using improper casing and brackets for built-in functions will immediately cause the script to fail and throw a syntax error.
Locate variables such as `Owner_#1_Loan_Period` in your calculation script. Delete the `#` symbol and rewrite them using standard camelCase formatting, such as `owner1LoanPeriod` and `owner1Age`.
Find instances of `math.min` and change them to `Math.min`. Standard JavaScript requires exact casing for built-in objects, and 'Math' must always be capitalized.
Replace square brackets with standard parentheses in your math equations. For example, update the script to read `event.value = Math.min(65 - owner1Age, 30);`.
Instead of declaring intermediate variables, you can read the form fields directly by inserting `this.getField("YourFieldName").value` directly into your calculation logic.

Edit and Manage PDF Forms Seamlessly with WPS Office
Simplify your workflow by using the built-in PDF tools in WPS Office. You can easily fill out, edit, and manage standard PDF forms without worrying about complex JavaScript syntax errors.
- 1. Open WPS Office: Launch WPS Office on your computer and select the 'PDF' module from the main dashboard.
- 2. Load your PDF Form: Click 'Open' and browse your files to select the PDF form document you need to work on.
- 3. Fill or Edit Fields: Navigate to the Form tab or simply click on the highlighted form fields to input your data, check boxes, or select dropdown options directly.
- 4. Save the Document: Click 'Save' or 'Export' to finalize your document and preserve all filled form data securely.

Frequently Asked Questions
What are the naming rules for JavaScript variables in PDF forms?
JavaScript variable names must begin with a letter, an underscore (_), or a dollar sign ($). They cannot contain spaces or special characters like #, %, or @. It is recommended to use camelCase, such as 'loanPeriod', for readability.
Why does Math.min return a syntax error in my script?
This usually happens due to incorrect casing, such as typing 'math.min' instead of 'Math.min', or using square brackets instead of parentheses for the arguments. It must be written exactly as Math.min(value1, value2).
How do I reference another field's value in Acrobat JavaScript?
You can retrieve the value of any form field by using the method this.getField('ExactFieldName').value in your custom calculation script, ensuring the exact field name is enclosed in quotes.




