Custom Calculation Script help

New Here ,
Feb 11, 2018 Feb 11, 2018

Copy link to clipboard

Copied

I have no java script or programming experience.

Trying to have a text field pre-fill based on the selection of any multiple dropdown boxes. Trying to auto fill the authority name that needs to sign when one or more dropdown has the appropriate selection. I can get it down with just one dropdown field but trying to make the pre fill appear if the selection appears in the other drop down.

var selectedPackage = this.getField ("Dropdown5.0").value;

if (selectedPackage=="K - RST") event.value= "COL, Chief of Staff";

// etc

else event.value = "";

I tried to repeat the script for each dropdown box name but either it just works for the first one or all 5 of the dropdown needs to be selected to "K"

TOPICS
Acrobat SDK and JavaScript

Views

272

Likes

Translate

Translate

Report

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

correct answers 1 Correct Answer

Adobe Community Professional , Feb 13, 2018 Feb 13, 2018
The problem is with your last line of code. Since you didn't use if-else if-else it only applies to your last if-statement, which means that most of the time the value will probably be empty (unless the last drop-down happens to be "K - RST after or on IDT").There are also several syntax errors in your code and it's quite of cumbersome. I would do it like this:event.value = "";var selectedPackageFields = this.getField("Dropdown5").getArray();for (var i in selectedPackageFields) {    if (selected...

Likes

Translate

Translate
Adobe Community Professional ,
Feb 12, 2018 Feb 12, 2018

Copy link to clipboard

Copied

Is this code in the calculation script for the text field? If it is, you are on the right track. What is the complete code you are using for handling the other dropdowns?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

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
New Here ,
Feb 13, 2018 Feb 13, 2018

Copy link to clipboard

Copied

Sorry was being a bit lazy. I couldn't copy and paste the code so I was typing out everything

var selectedPackage = this.getField ("Dropdown5.0").value;

if (selectedPackage=="K - RST after or on IDT") event.value="COL, Chief of Staff";

var selectedPackage = this.getField (Dropdown5.1").value;

if (selectedPackage=="K - RST after or on IDT") event.value="COL, Chief of Staff";

var (selectedPackage = this.getField (Dropdown5.2").value;

if (selectedPackage=="K - RST after or on IDT") event.value="COL, Chief of Staff";

var (selectedPackage = this.getField (Dropdown5.3").value;

if (selectedPackage=="K - RST after or on IDT") event.value="COL, Chief of Staff";

// etc.

else event.value = "";

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Feb 13, 2018 Feb 13, 2018

Copy link to clipboard

Copied

The problem is with your last line of code. Since you didn't use if-else if-else it only applies to your last if-statement, which means that most of the time the value will probably be empty (unless the last drop-down happens to be "K - RST after or on IDT").

There are also several syntax errors in your code and it's quite of cumbersome. I would do it like this:

event.value = "";

var selectedPackageFields = this.getField("Dropdown5").getArray();

for (var i in selectedPackageFields) {

    if (selectedPackageFields.value=="K - RST after or on IDT") {

        event.value="COL, Chief of Staff";

        break;

    }

}

Likes

Translate

Translate

Report

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
New Here ,
Feb 13, 2018 Feb 13, 2018

Copy link to clipboard

Copied

Maybe I'm doing something wrong but it only seems to work on the last dropdown only.

Sorry but if you could explain it bit more (again no java or programming experience)

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Feb 13, 2018 Feb 13, 2018

Copy link to clipboard

Copied

The code I provided should work. If it doesn't you'll need to share the file with us for further help.

Likes

Translate

Translate

Report

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
New Here ,
Feb 13, 2018 Feb 13, 2018

Copy link to clipboard

Copied

LATEST

Never mind I was being dumb and had accidentally inputted extra characters.

You guys are a big help with this

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Feb 13, 2018 Feb 13, 2018

Copy link to clipboard

Copied

Why can't you copy and paste?

Likes

Translate

Translate

Report

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
New Here ,
Feb 13, 2018 Feb 13, 2018

Copy link to clipboard

Copied

Not sure. it may be a setting that is stopping me from doing it. I tried to also right click and copy/paste but that also doesn't work.

Likes

Translate

Translate

Report

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