Skip to main content
Participating Frequently
December 1, 2017
Question

Submitting form based on 2 dropdown selections - Javascript

  • December 1, 2017
  • 9 replies
  • 1106 views

Literally a noob when it comes to javascripting. I'm wanting to send a pdf form based on 2 dropdown selections when selecting a submit button. I could be miles out or so close but literally have no idea of what I'm doing at this level. What I achieved so far is from scanning the web. ***Please note I am using a Adobe Acrobat Pro DC

Dropdown 1 = Head Office and Sub Team

Dropdown 2 = Constructive and Electrical

Code iv tried so far but its ignoring my command:

var Dropdown1 = this.getField("Dropdown1").value;

var Dropdown2 = this.getField("Dropdown2")value;

var email = "";

if ("Dropdown1" == "Head Office" && "Dropdown2" == "Constructive")

{

var email = "jasonsdking@me.com, constructive@hotmail.com";

}

else if ("Dropdown1" == "Head Office && "Dropdown2" == "Electrical")

{

var email = "jasonsdking@me.com, electrical@hotmail.com";

}

else if ("Dropdown1" == "Sub Team" && "Dropdown2" == "Constructive")

{

var email = "jasonsdking1@me.com, constructive@hotmail.com";

}

else if ("Dropdown1 == "Sub Team" && "Dropdown2" == "Electrical")

{

var email = "jasonsdking1@me.com, electrical@hotmail.com":

}

else

{

email = "kingysnewstart@Hotmail.co.uk"

}

if (email !="")

{

this.submissionForm({

c.URL: "mailto:" + email,

cSubmitAs: "PDF"

});

}

Currently it attaches to an email addressed to kingysnewstart@Hotmail.co.uk and blanks my commands of picking from the two drop downs. Please note all emails are fake except the personal ones jasonsdking@me.com and Kingysnewstart@Hotmail.com for privacy reasons., and that there will be 20+ emails addresses for each selection.

It would be ideal if  the title read - SRI: Dropdown1 Option + Dropdown 2 Option, and also that specific fields are filled in before sending (Text box 1 and text box 2)

Please assist if possible, probably asking a bit to much to be honest.

Regards

Jason King

This topic has been closed for replies.

9 replies

Legend
December 4, 2017

You're using app.alert to check the values of email, Dropdown1 and Dropdown2 ?

Legend
December 4, 2017

Is it really all like that, a single line? Or are you copy/pasting it in pieces for some reason? Or did the forum mess it up? Either way it's very hard to read. If you're having trouble with copy/paste please say what you do and what happens, this is an important thing to work.

Legend
December 4, 2017

Looking over it, though, here are some thoughts.

1. Try adding an app.alert line immediately before the if (email... line, to confirm the value of email.

2. If it isn't as expected also use app.alert to report on the values of Dropdown1 and Dropdown2.

3. You have an extra dot in c.URL I believe.

Participating Frequently
December 4, 2017

Still no luck. Its just ignoring all commands based on the results from the dropdowns

Legend
December 1, 2017

Sorry retyping, dang autocorrect.

Participating Frequently
December 4, 2017

var Dropdown1 = this.getField("Dropdown1").value;

var Dropdown2 = this.getField("Dropdown2").value;

var email = "";

if(Dropdown1 == "Head Office" && Dropdown2 == "Constructive")

{

email="Specific Email Addresses";

}

else if(Dropdown1 == "Head Office" && Dropdown2 == "Electrical")

{

email="Specific Email Addresses";

}

else if(Dropdown1 == "Sub Team" && Dropdown2 == "Constructive")

{

email="Specific Email Addresses";

}

else if(Dropdown1 == "Sub Team" && Dropdown2 == "Electrical")

{

email="Specific Email Addresses";

}

else

{

email="Specific Email Addresses"

}

if(email !="")

{

this.submitForm({

cURL: "mailto:" + email,

cSubmitAs:"PDF"

});

}

Specific email address will be added at my end when problem resolved.

I'm having problems with simply copying and paste and must click the HTML icon to be able to paste, then format goes all weird.

Thom Parker
Community Expert
Community Expert
December 4, 2017

Are there any errors reported in the Console?

Here's a tutorial on the topic.

https://www.pdfscripting.com/public/images/Free_Videos/BeginJS_Console_Alt_mp4.cfm

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Legend
December 1, 2017

It’s extremely important to find how to copy and paste. Retrying will not cut it.

Legend
December 1, 2017

Your code seems to have been edited and ruined by a moderator, I can no longer make head or tail out of it. Try pasting again but change any personal info or email. Also don’t leave in anything like a html < tag >

Legend
December 1, 2017

You just need to look in the JavaScript window after you click the button. Any messages?

Also please paste the code exactly as it is today. The combination of code and messages may help us help you fix your code. Please don’t ask us to write it for you.

Participating Frequently
December 1, 2017

No message at all.

Code is exactly:

var Dropdown1 = this.getField("Dropdown1").value;

var Dropdown2 = this.getField("Dropdown2").value;

var email = "";

if(Dropdown1 == "Head Office" && Dropdown2 == "Constructive")

{

email="Specific Email Addresses";

}

else if(Dropdown1 == "Head Office" && Dropdown2 == "Electrical")

{

email="Specific Email Addresses";

}

else if(Dropdown1 == "Sub Team" && Dropdown2 == "Constructive")

{

email="Specific Email Addresses";

}

else if(Dropdown1 == "Sub Team" && Dropdown2 == "Electrical")

{

email="Specific Email Addresses";

}

else

{

email="Specific Email Addresses"

}

if(email !="")

{

this.submissionForm({

c.URL: "mailto:" + email,

cSubmitAs:"PDF"

});

}

Specific email address will be added at my end when problem resolved.

try67
Community Expert
Community Expert
December 1, 2017

You didn't fix the errors I pointed out with submitForm and the cURL parameter.

Legend
December 1, 2017

What does it now say in the console when this code is run?

Participating Frequently
December 1, 2017

Sadly your dealing with an idiot when it comes to this stuff so sorry if its like speaking to a child and is frustrating. Not sure what you mean by what does it say in console when the code is run but when I Ok in the Create and Edit Javascripts window it shows no errors. I then go into preview mode and press the submit button. With even Dropdown1 as Sub Team and Dropdown2 as Electrical selected it ignores the written commands of who to email specifically and processes this part of the command:

else

{

email = kingysnewstart@Hotmail.co.uk

}

If you could write out how the code should exactly read it would defo be more helpful. Again I can understand if you wish not to.

Thanks

Legend
December 1, 2017

Also, you write

if ("Dropdown1" == "Head Office" && "Dropdown2" == "Constructive")

This is just saying: does the string "Dropdown1" equal the string

"Head Office" (etc.) Of course, it never does. You want the VALUE OF

THE VARIABLE Dropdown1, not the string "Dropdown1". When you want the

value of the variable, don't put that in quotes.

Participating Frequently
December 1, 2017

I removed the quotes and still no luck

try67
Community Expert
Community Expert
December 1, 2017

If that's your real code it shouldn't work at all, as you used an incorrect function name ("submissionForm").

Replace that part with:

this.submitForm({

     cURL: "mailto:" + email,

     cSubmitAs: "PDF"

});

Also, drop the "var" keyword before the email variable in all places except for the first instance.

try67
Community Expert
Community Expert
December 1, 2017

It would be ideal if  the title read - SRI: Dropdown1 Option + Dropdown 2 Option, and also that specific fields are filled in before sending (Text box 1 and text box 2)

- Read up on the mailto syntax. You can specify the subject line just like the target email addresses

- Set the fields as required to force their validation before the file is submitted.