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

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

634

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

Community Expert , 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

...

Votes

Translate

Translate
Community Expert ,
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

Votes

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 = "";

Votes

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
Community Expert ,
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;

    }

}

Votes

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)

Votes

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
Community Expert ,
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.

Votes

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

Votes

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

Copy link to clipboard

Copied

Why can't you copy and paste?

Votes

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.

Votes

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