How to Concatenate Variables and Strings in PDF JavaScript
Question details
The user needs to know how to properly combine variables and strings in PDF form JavaScript without triggering syntax errors.

- Product
- Adobe Acrobat PDF
- Device & OS
- not provided
- Scenario
- Writing custom JavaScript calculations or actions for interactive PDF forms.
- Observed behavior
- Using modern ES6 template literals (backticks) or keywords like 'const' causes syntax errors in legacy PDF JavaScript engines.
Before modifying your form scripts, ensure you have access to a PDF editor that supports form field JavaScript editing, and back up your original PDF file.
Use the Standard String Concatenation Operator (+)
Replace ES6 template literals with the traditional plus operator for maximum compatibility across all PDF readers.
Many PDF readers utilize legacy JavaScript engines that do not support modern ES6 syntaxes, such as template literals (backticks) or block-scoped variables ('let' and 'const').
By replacing these modern elements with traditional JavaScript syntax, you ensure your PDF form calculations and text generation work seamlessly across all viewers.
Open your interactive PDF form in edit mode and right-click the specific form field to access its Properties.
Locate the tab where your custom JavaScript is executed, such as the Calculate tab or a specific Mouse Up action trigger.
Change any modern ES6 variable declarations like 'const' or 'let' to the older 'var' keyword. For example, write: var cARm = 5;
Remove ES6 backtick template literals. Replace them with standard quotes and the plus (+) operator. For example, instead of `${cARm} mL-removed`, write: var removed = cARm + ' mL-removed';
Click OK to save the script, then test the form field to ensure the strings and variables concatenate properly without throwing syntax errors.

Edit and Manage PDF Forms Seamlessly with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to easily view, fill, and manage interactive PDF forms without dealing with complex software configurations.
- 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and install it on your computer.
- 2. Open Your PDF File: Launch WPS PDF and open the interactive form you need to manage or fill out.
- 3. Edit or Fill the Form: Use the PDF editing and form tools to input data, manage your document content, and save your progress effortlessly.

Frequently Asked Questions
Why do template literals (backticks) cause errors in PDF forms?
Many PDF readers use older, legacy JavaScript engines that were developed before modern ES6 standards were introduced. As a result, they do not recognize syntax like template literals or the 'const' keyword, resulting in script failures.
Can I use 'let' or 'const' in PDF JavaScript?
It is highly recommended to use 'var' instead of 'let' or 'const'. Using 'var' ensures maximum compatibility across various PDF readers, especially those built on older software frameworks.
How do I test my PDF JavaScript for syntax errors?
You can open the built-in JavaScript console in advanced PDF editors (often accessible via Ctrl+J or Cmd+J) to view detailed syntax errors or runtime exceptions when interacting with form fields.




