How to Fix Acrobat JavaScript Error When Setting Email Subject
Question details
The user needs to resolve a JavaScript error that prevents them from automatically setting an email subject via script in a PDF form.

- Product
- Adobe Acrobat PDF Forms
- Device & OS
- not provided
- Scenario
- Adding a script to a PDF form (such as a submit button) that uses variables to dynamically generate an email subject and trigger the mailDoc function.
- Observed behavior
- A JavaScript error prompt appears, specifically citing 'invalid assignment left-hand side', often caused by undefined variables or using incompatible LiveCycle Designer code in a standard Acrobat AcroForm.
Verify whether your PDF form was created as a standard Acrobat AcroForm or an Adobe LiveCycle Designer form, as their JavaScript object models differ significantly and require different syntax.
Correct the JavaScript Syntax for Acrobat AcroForms
Replace any incompatible LiveCycle Designer variables with standard Acrobat JavaScript syntax to properly execute the mailDoc function without errors.
Acrobat AcroForms do not support LiveCycle objects like 'rawValue'. You must declare standard variables for your email fields and use the Acrobat-specific syntax to retrieve field values before passing them to the mail script.
Declare variables for 'to', 'cc', 'subject', and 'emailMsg' at the beginning of your script to ensure no undefined variables are passed.
Use the standard syntax this.getField("YourFieldName").value to get data from the form, rather than trying to assign a value to an invalid left-hand side element.
Call the app.mailDoc method using the defined variables. For example: app.mailDoc({bUI: true, cTo: to, cSubject: subject, cMsg: emailMsg});
Right-click your PDF form button, select Properties, navigate to the Actions tab, choose 'Run a JavaScript', and paste your corrected, error-free code into the editor.

Manage and Share Interactive PDF Forms with WPS Office
WPS Office offers a robust built-in PDF editor that allows you to effortlessly fill, edit, and share interactive PDF forms without dealing with complex JavaScript debugging.
- 1. Open your PDF in WPS: Launch WPS Office and open your interactive PDF form using the built-in WPS PDF tool.
- 2. Fill out the form fields: Click directly into the text boxes, checkboxes, or dropdowns to complete the form securely.
- 3. Use the Share tool: Instead of writing complex JavaScript for a submit button, navigate to the top toolbar and click the 'Share' or 'Email' icon.
- 4. Send via default mail client: WPS PDF will automatically attach your filled form to a new email draft in your system's default email client, ready for you to add a subject and send.

Frequently Asked Questions
What causes the 'invalid assignment left-hand side' error in Acrobat?
This error generally occurs when your script attempts to assign a value to an item that cannot receive it, such as a function result or a reserved JavaScript keyword. In PDF forms, it frequently happens if LiveCycle Designer syntax is accidentally pasted into a standard AcroForm script editor.
How do I check if my PDF is an AcroForm or a LiveCycle Designer form?
Open your PDF document and access the Document Properties (Ctrl+D or Cmd+D). Under the Description tab, check the 'Application' or 'PDF Producer' field. LiveCycle forms will explicitly mention Adobe LiveCycle Designer, whereas AcroForms will typically list Adobe Acrobat or standard PDF generators.
How do I automatically set the email subject when a user clicks submit?
You can use the app.mailDoc() method in JavaScript. Pass an object containing the parameter cSubject (e.g., {cTo: "email@example.com", cSubject: "Your Subject Here"}). This tells Acrobat to pass that specific subject line to your default email client.
Why isn't my mailDoc script opening my email client?
The mailDoc function requires that your operating system has a default email client properly configured (such as Outlook, Apple Mail, or Thunderbird). Additionally, ensure your script has no syntax errors and all referenced field variables actually exist in the PDF form.




