Skip to main content
Participating Frequently
January 5, 2024
Question

JavaScript that will send form to recipients that are based on the value selected in a dropdown

  • January 5, 2024
  • 1 reply
  • 3747 views

I created a PDF form using Adobe Acrobat that is designed to capture information and then allow the user to send the completed form to the people who need the information using a "Send" button.

 

I am brand spanking new to making forms (newer to code) and the code below I got from research on the internet. The code is in the button properties under Actions and Run a Javascript. It is included here for reference. It works very well if the email recipients do not change.

```

var cToAddr = "Email1@work.com;Email2@work.com;Email3@work.com";
var cCCAddr = "CCMail@work.com";
var cSubLine = "[Student Name / Employee Number] Situation";
var cBody = "Enter other information as desired."
this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});


```

Now I need the form to go to different recipients based on the value selected from a drop-down menu on the form. For example, if Team 1 is selected from the dropdown, then I need the form to go to Team1@email.com. If Team 2 is selected, then I need the form to go to Team2@email.com, etc.

 

I do not know how to modify this code to make this happen nor have I been able to find new code that would do this and need assistance.

 

I've read Thom Parker's November 4, 2013 post (Form sbubmit /eMail demystified) but am probably too new at this to get the answer that I need, though I have learned a little. 

 

Is there a way to modify the current code (above) or could someone provide the proper code to achieve this function? I am sure that it is possible, and probably quite simple, I just can't figure it out. 

This topic has been closed for replies.

1 reply

try67
Community Expert
January 5, 2024

See: https://acrobatusers.com/tutorials/dynamically-setting-submit-e-mail-address

Basically, all you need to do is place the email address as the export value of each item in the drop-down and then just use that field's value in your code, like this:

 

var cToAddr = this.getField("Team").valueAsString;

Participating Frequently
January 6, 2024

So here is the code I have now (names changed to protect the innocent...)

var cToAddr = this.getField("Team").valueAsString;
var cCCAddr = "First.Last@work.com";
var cSubLine = "[Student Name / Employee Number] Not Recommended";
var cBody = "Enter other information as desired."
this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});

I kind of understand now what this is doing. The Export Value for each of the four teams in the dropdown menu now have the actual emails for the individuals who need to receive the form. 

 

However, something is not working because the code no longer does the first step of opening the email...

 

What have I done incorrectly?

 

 

Participating Frequently
January 7, 2024

PS. You can use this method to pre-populate the subject line as well, if that information is available in a form field.


Interesting that you brought that up.

 

Trying to keep the form as simple as possible, I started experimenting with if, else if statements to populate the CC line based on those same selections. I tried the following but keep getting a SyntaxError: missing ; before statement.

 

With "Fleet" being the name of the dropdown...

 

if (“Fleet” = Team1) {
	var cCCAddr = “People1@Work.com”;
} else if ("Fleet" = Team2) {
	var cCCAddr = "People2@Work.com";
} else {
	var cCCAddr = “”;
}

 

Of course, if there is a better way to address this I am all ears. With the "To" addresses in the Export Value property, this was the only workaround I could think of based on my limited experience.