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

Javascript - Email Button, based off of radio button Selection, and select email subject

Community Beginner ,
Jun 22, 2023 Jun 22, 2023

Hello, 

I have a form that I want to send VIA a submit button to a variable email address based off of an earlier selection in a radio button. 

I am new to JavaScript, This is what I have so far, although I know this is not correct. 

this.submitForm(
"mailto:mm@mycom.com?" +
"&cc=123@abc.com" +
"&subject= [ID CODE] + "[Customer Name]"
);
cSubmitAs:"PDF"
});

What I need to happen is below.

My form has a radio selection button with 5 options
If option 1 is selected then email 1@abc.com + CC anna@abc.com
If option 2 is selected then email 2@abc.com + CC anna@abc.com
and so on...

for the subject line I want it to pull 2 fields from the form Client Number + Client Name after Template Submission
For Example Client Number is 1234 and name is Joe Smith 
The subject should read Template Submission 1234 - Joe Smith

And lastly I need the attachment of the form to be PDF version 

Thank you in advance for your expertise!

TOPICS
How to , JavaScript , PDF , PDF forms
1.2K
Translate
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 ,
Jun 22, 2023 Jun 22, 2023
Translate
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 ,
Jun 22, 2023 Jun 22, 2023

Thank you, I did locate this on my search but so far have not been successful in executing the javascript. I keep getting Syntax errors that I don't know how to fix. 

Translate
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 ,
Jun 22, 2023 Jun 22, 2023

Post the code you're using and we'll help you fix it.

Translate
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 ,
Jun 22, 2023 Jun 22, 2023

PS. You should switch to using mailDoc, instead of submitForm. It's more flexible, although it doesn't validate the required fields before submitting the file, if that's something that you rely on...

Translate
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 ,
Jun 22, 2023 Jun 22, 2023

Thank you, 

What I have so far which is not complete but is so far the last variation I have tried is:
this.submitForm(
"mailto:mm@mycom.com?" +
"&cc=123@abc.com" +
"&subject= [ID CODE] + "[Customer Name]"
);
cSubmitAs:"PDF"
});


I did also attempt an if statement but I have since deleted that so I can't post it however, it failed. 

I do use a lot of form validations within this form, but that is great information in the future when I do not need the validations. 

I sincerely appreciate your help! 

Translate
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 ,
Jun 22, 2023 Jun 22, 2023

Ah I found it! 

this.submitForm(
"mailto:mm@mycom.com?" +
"&cc=123@abc.com" +
"&subject= [ID CODE] + "[Customer Name]"
);
cSubmitAs:"PDF"
});

 

Translate
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 ,
Jun 22, 2023 Jun 22, 2023

if ( CE Team == "CE 1" )

 

this.submitForm(
"mailto:mm@mycom.com?" +
"&cc=123@abc.com" +
"&subject= [ID CODE] + "[Customer Name]"
);
cSubmitAs:"PDF"
});

Translate
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 ,
Jun 22, 2023 Jun 22, 2023

I have gotten to this point so far
var cMailSelect = this.getField("CE Team").value; if(cMailSelect == "CE 1")this.submitForm ("mailto:1@abc.com;" +
"anna@abc.com")

However this puts "anna" in the to section not the CC section as I want. 

Translate
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 ,
Jun 23, 2023 Jun 23, 2023

Right, because that's what you told it to do. Read the documentation of the mailto syntax to learn how to specify a CC address, a subject line, etc.: https://yoast.com/developer-blog/guide-mailto-links/

 

Translate
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 ,
Jun 23, 2023 Jun 23, 2023
LATEST

Thanks for your assistnace I was able to get it correct yesterday for all the areas I needed !

Translate
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