How to Create an Email Address from a PDF Form Name Field via JavaScript
Question details
The user wants to automatically generate an email address (e.g., john.smith@domain.com) by extracting the first and last name from a PDF form text field and attaching this action to an email button.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where an email submission button dynamically formats a user's name into a company email address.
- Observed behavior
- The user requires a JavaScript snippet that can read the text input, replace spaces with periods, convert the string to lowercase, and append the specific email domain.
Ensure your PDF editor supports JavaScript execution for form fields and take note of the exact Field Name (e.g., 'Name') containing the user's input before applying the script.
Use Document JavaScript to Auto-Format the Email Address
Apply a custom JavaScript action to the email button to read the Name field, format the text, and prepare the resulting string for the email client.
You can use standard PDF JavaScript to manipulate text strings from form fields. By reading the text value, converting it to lowercase, and replacing spaces with dots, you can dynamically construct a valid email address.
Please note that invoking email clients via JavaScript might prompt security warnings depending on the user's PDF viewer settings. Ensure your PDF reader is configured to allow these actions.
Open your PDF form in edit mode, locate the button you want to use for generating the email, right-click it, and open its Properties.
Navigate to the 'Actions' tab, select 'Run a JavaScript' from the 'Select Action' dropdown menu, and click 'Add'.
In the JavaScript Editor, enter the script to read and format the name field: var name = this.getField("Name").valueAsString.trim().toLowerCase(); (Ensure "Name" matches your exact text field name).
Add the formatting script to replace the space and append the domain: var cToAddr = name.replace(/\s+/, ".") + "@jet.com.au"; (Replace @jet.com.au with your actual domain).
Use the resulting address in your email action script by adding: app.mailMsg({bUI: true, cTo: cToAddr, cSubject: "Form Submission"}); and click 'OK' to save.

Create and Edit Interactive PDF Forms with WPS Office
WPS PDF provides comprehensive tools for creating interactive PDF documents, enabling you to add text fields, insert clickable buttons, and manage form submission properties with ease.
- 1. Open PDF in WPS Office: Launch WPS Office and open your PDF form document using the WPS PDF editor.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to reveal the interactive form controls.
- 3. Insert Form Fields: Select 'Text Field' or 'Push Button' and click on the page to insert the element.
- 4. Configure Properties: Right-click the inserted field or button and select 'Properties' to adjust names, appearances, and specific actions.

Frequently Asked Questions
Why isn't the JavaScript button triggering my email client?
Your PDF viewer's security settings may restrict scripts from launching external applications like email clients. You may need to check the 'Trust Manager' or security preferences in your PDF reader to allow external links or mail actions.
Can I use this script on a web browser PDF viewer?
Most built-in web browser PDF viewers (like Google Chrome or Microsoft Edge) have very limited support for PDF JavaScript and advanced form actions. Users typically need a dedicated desktop application like WPS PDF or Adobe Acrobat to execute these scripts properly.
How do I change the domain name in the script?
Simply modify the text string inside the quotation marks in the script from "@jet.com.au" to your desired domain, such as "@yourcompany.com". Make sure to keep the quotation marks intact.
What if the user leaves the Name field blank?
If the field is blank, the script will generate an invalid email address (e.g., @domain.com). You can add an IF statement in your JavaScript to check if the 'name' variable is empty and prompt the user to fill it out before proceeding.




