Skip to main content
Participant
February 12, 2018
Answered

Custom Calculation Script help

  • February 12, 2018
  • 1 reply
  • 1259 views

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"

This topic has been closed for replies.
Correct answer try67

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;

    }

}

1 reply

Thom Parker
Community Expert
Community Expert
February 12, 2018

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
Ghost0mckAuthor
Participant
February 13, 2018

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

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 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 (selectedPackageFields.value=="K - RST after or on IDT") {

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

        break;

    }

}