PDF Editing Issues

How to Create an Email Address from a PDF Form Name Field via JavaScript

Kushani NimanthikaKushani Nimanthika Nov 3, 2026 869 views

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.

How to Auto-Generate an Email Address from a PDF Form Name Field
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.
Before you start

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.

Solution 1Recommended

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.

1
Locate the Email Button

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.

2
Add a JavaScript Action

Navigate to the 'Actions' tab, select 'Run a JavaScript' from the 'Select Action' dropdown menu, and click 'Add'.

3
Initialize the Name Variable

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).

4
Format and Append the Domain

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).

5
Trigger the Email Action

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.

Use Document JavaScript to Auto-Format the Email Address
Handling Multiple Spaces: The basic regex /\s+/ replaces only the first space. If you anticipate middle names and want periods between all names, use a global regex like /\s+/g instead.
Easily Manage Interactive PDF Forms

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. 1. Open PDF in WPS Office: Launch WPS Office and open your PDF form document using the WPS PDF editor.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to reveal the interactive form controls.
  3. 3. Insert Form Fields: Select 'Text Field' or 'Push Button' and click on the page to insert the element.
  4. 4. Configure Properties: Right-click the inserted field or button and select 'Properties' to adjust names, appearances, and specific actions.
Easily add text fields, checkboxes, and interactive buttons to PDFs.Highly compatible with standard PDF form formats and structures.Lightweight, fast, and features an intuitive user interface.Seamlessly fill out, save, and print interactive PDF forms.
microsoft office alternative - wps office

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.