Other PDF Issues

Add PDF Form Field Value to Email Subject Using JavaScript

Jason MillerJason Miller Nov 5, 2026 869 views

Question details

The user wants to dynamically populate an email subject line with a value selected from a PDF drop-down form field using JavaScript.

How to Add a PDF Form Field Value to an Email Subject Using JavaScript
Product
PDF
Device & OS
not provided
Scenario
Creating an interactive PDF form that sends an email upon clicking a button, where the subject line reflects the user's input.
Observed behavior
The desired behavior is that clicking the email submit button reads the value from a specific drop-down field (e.g., "LocationD") and correctly concatenates it into the subject parameter of the email draft.
Before you start

Ensure your PDF editing software supports JavaScript for interactive forms and that you know the exact name of the form field you want to reference.

Solution 1Recommended

Use getField and mailDoc in PDF JavaScript

Retrieve the specific form field value as a string and insert it into the mailDoc function's subject parameter.

You can use built-in JavaScript functions in advanced PDF software to read user input dynamically. By fetching the field value and combining it with your standard subject text, you can create customized email subjects for each submission.

1
Access the Button Properties

Right-click the submit button in your interactive PDF form and select 'Properties'. Navigate to the 'Actions' tab.

2
Add a JavaScript Action

Under 'Select Action', choose 'Run a JavaScript' from the drop-down menu, then click the 'Add' button to open the JavaScript editor.

3
Enter the JavaScript Code

Use the getField method to read the value and the mailDoc method to trigger the email. For example: var location = this.getField("LocationD").valueAsString; var subjectLine = "Location: " + location; this.mailDoc({cTo: "target@email.com", cSubject: subjectLine, cMsg: "Thank you"});

4
Save and Test

Click 'OK' to save the script, close the properties dialog, and exit form editing mode. Click the button to test if your default email client opens a draft with the correct subject.

Field Name Accuracy: Make sure the field name inside the getField() method exactly matches the name of your drop-down field, including capitalization, otherwise the script will return an error.

Edit and Manage PDF Forms Easily with WPS Office

WPS Office provides robust PDF editing tools, allowing you to create interactive forms, manage text fields, and handle document workflows efficiently without relying on complicated or expensive software.

  1. 1. Open your PDF: Launch WPS Office and open your interactive PDF document.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to view and edit form fields, drop-downs, and buttons.
  3. 3. Edit Properties: Double-click any form field to easily adjust its properties, names, and associated actions.
Easily insert, edit, and manage PDF form fields and buttonsSeamlessly compatible with standard Adobe PDF formats and Microsoft Office filesCreate professional PDF documents with an intuitive, user-friendly interfaceFree and lightweight alternative to heavy PDF editors
microsoft office alternative - wps office

Frequently Asked Questions

Why is my getField("FieldName").value returning undefined?

This typically happens if the field name is misspelled or if the case does not exactly match. Check the exact field name in your PDF's form properties. Using .valueAsString instead of .value is also highly recommended to ensure the output is properly treated as text.

Can I include multiple form fields in the email subject?

Yes, you can declare multiple variables for different fields (e.g., var field1 = this.getField("Field1").valueAsString; var field2 = this.getField("Field2").valueAsString;) and concatenate them all into the subject line variable using the + operator.

Does the mailDoc function automatically send the email in the background?

No. For security and anti-spam reasons, the mailDoc function only opens the user's default desktop email client (like Outlook or Apple Mail) with a new draft populated with your parameters. The user must manually review and click 'Send'.

What if the user relies on a web-based email client?

PDF JavaScript's mailDoc relies on the default mail handler configured on the user's operating system. If they do not have a default desktop client configured, the submit button may fail to open an email draft.