• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
5

Email Form button with Javascript

Community Beginner ,
Mar 05, 2024 Mar 05, 2024

Copy link to clipboard

Copied

I apologize in advance if this is answered multiple times, I just could not find what I needed.

 

I am trying to have a button send my form (as an attachment) to hard-coded email addresses as well as email addresses based on field values while also having a Subject line and Body determined by the JavaScript.

 

Based on what I found, here is my Javascript (added under "Button Properties">"Actions">"Mouse Up" Trigger>"Run a JavaScript" Action):

 

var cToAddr = this.getField("first.last@website.com").value;
var cCcAddr = this.getField("Preparer Email").value;
var cSubLine = this.getField("Location Name").valueAsString + " " + this.getField("Change Type").valueAsString + " " + "COS Request" + " " + this.getField("Date_af_date").valueAsString;
var cBody = "Please see the attached COS form for immediate processing.\n" + "Save the form for your own records."
this.mailDoc({bUI:true, cTo: cToAddr,cCc: cCcAddr,cSubject: cSubLine, cMsg: cBody});

 

I don't get any Syntax errors, but when I test it and click the button, nothing happens...

 

I'm a rookie at JS, but am working to learn more.

 

*Bonus points if you have any tips for populating multiple email addresses based on a dropdown field value (EX: If dropdown value is "A", I need the email to be sent to Email(s) 1,2,3,4, & 5. If dropdown value is "B", the email needs to go to 2,4,6, & 8). I figure I might need hidden text fields for each dropdown value with the emails listen in them?

TOPICS
JavaScript , Modern Acrobat , PDF forms

Views

613

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 06, 2024 Mar 06, 2024

I thought so... Yes, that is how it should be. And your previous code should have generated an error message, saying the field is null. Did you check the JS Console?

Regarding the "bonus" question, just enter the multiple addresses as the export value of the items in the drop-down field, separated by semi-colons.

Votes

Translate

Translate
Community Expert ,
Mar 06, 2024 Mar 06, 2024

Copy link to clipboard

Copied

You have a field called "first.last@website.com"?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 06, 2024 Mar 06, 2024

Copy link to clipboard

Copied

Well that's embarassing....

 

No, that is supposed to be the hard-coded email address it is sent to in every case (address was edited for privacy). That's what too much copy/paste gets me I guess!

 

Shoud that line just be:

var cToAddr = "first.last@website.com";

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 06, 2024 Mar 06, 2024

Copy link to clipboard

Copied

I thought so... Yes, that is how it should be. And your previous code should have generated an error message, saying the field is null. Did you check the JS Console?

Regarding the "bonus" question, just enter the multiple addresses as the export value of the items in the drop-down field, separated by semi-colons.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 06, 2024 Mar 06, 2024

Copy link to clipboard

Copied

LATEST

I wasn't getting an error message for some reason. I hadn't checked JS console, but I'll look into that because I wasn't aware of it.

 

(Bonus) Ok good deal, I'll give that a shot!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines