Skip to main content
Participant
March 5, 2024
Answered

Email Form button with Javascript

  • March 5, 2024
  • 1 reply
  • 1805 views

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?

This topic has been closed for replies.
Correct answer try67

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.

1 reply

try67
Community Expert
Community Expert
March 6, 2024

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

Participant
March 6, 2024

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";

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 6, 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.