PDF Editing Issues

How to Combine PDF Form JavaScript to Hide Fields and Send Email

Tauseeq MagsiTauseeq Magsi Nov 3, 2026 868 views

Question details

The user needs to create a unified JavaScript function for a PDF form that conditionally hides or shows an email field based on a checkbox, composes a custom email using form data, and sends the PDF while hiding specific interface buttons.

How to Combine PDF Form JavaScript to Hide Fields and Send Email
Product
PDF Form
Device & OS
not provided
Scenario
Configuring interactive PDF form buttons to process form data conditionally and automate the email submission process without UI glitches.
Observed behavior
Using separate button actions for visibility and email submission causes logic conflicts; the actions must be combined into a single logical JavaScript workflow to function correctly.
Before you start

Before modifying your PDF form, ensure your PDF editor supports JavaScript execution for form fields and verify the exact names of your target form fields to prevent script errors.

Solution 1Recommended

Combine Conditional Logic and the mailDoc Function

Use a single unified JavaScript block on your submit button's 'Run a JavaScript' action to handle field visibility, dynamic data extraction, and email sending simultaneously.

Instead of assigning multiple separate actions to a button, combining them into one script prevents execution order issues. By checking if a specific box is checked first, you can dynamically display the email field or execute the mailDoc() method securely in one pass.

1
Access Button Properties

Open your PDF form in Edit Mode, right-click the submit button you want to configure, and select Properties from the context menu.

2
Add a JavaScript Action

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

3
Define Field Variables and Conditions

Enter your script by first defining the variable for your checkbox: `var visible = this.getField("HiddenCheck");`. Add an if-statement to check its status: `if (visible.isBoxChecked(0) == false) { this.getField("EmailAddress").display = display.visible; }`.

4
Configure the Email Action

In the `else` block, set your email parameters by extracting field values. For example: `var cToAddr = this.getField("EmailAddress").value;` and `var cSubLine = "Agreement for " + this.getField("OtherPartyName").value;`.

5
Hide Fields and Trigger mailDoc

Hide the email field using `this.getField("EmailAddress").display = display.hidden;`, then trigger the email window using `this.mailDoc({bUI: true, cTo: cToAddr, cFromAddr: "your@email.com", cSubject: cSubLine, cMsg: "Your message"});`.

6
Save and Test

Click OK to close the JavaScript Editor and close the Properties dialog. Preview the PDF and test the button to ensure it hides the required fields and opens your default email client.

Combine Conditional Logic and the mailDoc Function
Button Visibility Tip: If you need the submit button itself to disappear before generating the email, add `this.getField("YourButtonName").display = display.hidden;` immediately before the `this.mailDoc(...)` function call.
Manage PDFs with WPS Office

Easily Edit PDF Forms and Manage Documents with WPS Office

WPS PDF provides robust tools for filling, editing, and managing interactive PDF forms. Whether you need to process form data, add digital signatures, or convert PDFs to other file formats, WPS Office offers a comprehensive and user-friendly experience.

  1. 1. Download WPS Office: Download and install WPS Office from the official website to access the comprehensive WPS PDF tool.
  2. 2. Open Your PDF File: Launch WPS PDF and open your interactive PDF form document.
  3. 3. Fill and Manage Forms: Navigate to the Form tab to interact with form fields, checkboxes, and buttons seamlessly.
  4. 4. Save and Share: Once your form is filled, save your document or use the built-in sharing tools to distribute it securely.
Easily fill and manage interactive PDF form fields.Fully compatible with standard PDF formats and Adobe form structures.Seamless integration with Word, Excel, and PowerPoint alternatives.Lightweight software with a familiar, easy-to-use interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't my mailDoc() JavaScript triggering the email client?

This usually happens if your default email client is not configured correctly on your operating system, or if security restrictions within your PDF viewer are blocking JavaScript execution. Ensure your default mail app is set up and that the PDF reader has permissions to execute scripts.

Can I hide the submit button immediately after a user clicks it?

Yes, you can hide the button by including `this.getField("ButtonName").display = display.hidden;` in your JavaScript. Place this line before the `mailDoc()` call so the button disappears from the document before the email is generated.

How do I reference another field's value in my PDF email subject line?

You can retrieve another field's value using the `getField` method in your JavaScript. For example, `var subject = "Agreement for " + this.getField("ClientName").value;` will seamlessly append the text entered in the 'ClientName' field to your email subject line.