I have a form with a drop down field that, based on the selection, changes the email recipient in the submit button. Basically "if dropdown = A", email recipient is "john smith", if dropdown = B, email recipient is "bill jones", if dropdown = C, email recipient is "mary doe", etc. Not sure how to code this.
Solved! Go to Solution.
Views
Replies
Total Likes
I'm confident that you already figured this out but since nobody replied I thought I'd share what I've done in the past in case it helps anyone else.
In your drop down object Field List Items, type in your values in the Field list items. I made them A, B, & C
In your email button (I named the button "emailRecipient" in the hierarchy) CLICK event:
//Checks for the selection - if empty sets focus and changes border color red
if (form1.page1.recipientEmail.rawValue == null)
{
xfa.host.setFocus(form1.page1.recipientEmail.rawValue);
form1.page1.recipientEmail.border.edge.color.value = "230,0,0";
}
//Choose email based on Recipient value
var recipient_email = "bogusemail@google.com";
var recipient = form1.page1.recipientEmail.rawValue;
if(recipient == "A"){
recipient_email = "John.Smith@email.com"
}
else if(recipient == "B"){
recipient_email = "Bill.Jones@email.com"
}
else if(recipient == "C"){
recipient_email = "Mary.Doe@email.com"
}
//Check to see if all required fields are completed
if (form1.page1.recipientEmail.rawValue != null)
{
var oDoc = event.target;
oDoc.mailDoc({
bUI: true,
cTo: recipient_email,
cCC: "",
cSubject: "place your subject here ",
cMsg: "place your message here"
});
}
else
{
xfa.host.messageBox("Please complete the required fields");
}
In your EXIT event within the recipientEmail drop down list object use this code to remove red border after a value is entered by the user:
if(this.rawValue != null)
{
this.border.edge.color.value = "255,255,255"; //Revert the highlighted border
}
I've made a mockup form for easy reference:
https://drive.google.com/drive/folders/1eJj4GnRvVn39Os90slqxudqTluqFM5QP?usp=sharing
I'm confident that you already figured this out but since nobody replied I thought I'd share what I've done in the past in case it helps anyone else.
In your drop down object Field List Items, type in your values in the Field list items. I made them A, B, & C
In your email button (I named the button "emailRecipient" in the hierarchy) CLICK event:
//Checks for the selection - if empty sets focus and changes border color red
if (form1.page1.recipientEmail.rawValue == null)
{
xfa.host.setFocus(form1.page1.recipientEmail.rawValue);
form1.page1.recipientEmail.border.edge.color.value = "230,0,0";
}
//Choose email based on Recipient value
var recipient_email = "bogusemail@google.com";
var recipient = form1.page1.recipientEmail.rawValue;
if(recipient == "A"){
recipient_email = "John.Smith@email.com"
}
else if(recipient == "B"){
recipient_email = "Bill.Jones@email.com"
}
else if(recipient == "C"){
recipient_email = "Mary.Doe@email.com"
}
//Check to see if all required fields are completed
if (form1.page1.recipientEmail.rawValue != null)
{
var oDoc = event.target;
oDoc.mailDoc({
bUI: true,
cTo: recipient_email,
cCC: "",
cSubject: "place your subject here ",
cMsg: "place your message here"
});
}
else
{
xfa.host.messageBox("Please complete the required fields");
}
In your EXIT event within the recipientEmail drop down list object use this code to remove red border after a value is entered by the user:
if(this.rawValue != null)
{
this.border.edge.color.value = "255,255,255"; //Revert the highlighted border
}
I've made a mockup form for easy reference:
https://drive.google.com/drive/folders/1eJj4GnRvVn39Os90slqxudqTluqFM5QP?usp=sharing
thanks...worked like a charm.