Skip to main content
Participant
April 19, 2023
Answered

How to populate a field depending on TWO drop down menu entries?

  • April 19, 2023
  • 1 reply
  • 3140 views

Hello everyone,

I'm quite new to using javascript on Acrobat, and I'm running into the following issue:

I have a form that would return a specific value depending on what's been selected in two drop down menus.

The first drop down menu shows a list of aircrafts which have two power settings (and the two power settings are set on the second drop down menu)... So first dropdown shows the aircraft registration, the second will show what power setting is being used (ie, max range, or max speed). Each power setting will use two different fuel flows. And the fuel flow is what I would like to populate the cells with...

I've written the following which would show both fuel flows, but I'm not quite sure how I should set it up on Acrobat...

G-WKTH    "{'departure’: '16’, 'endurance’: '10', 'transit’: '13.8', 'final_res': '10.5'}"
G-WKTI    "{'departure’: '16’, 'endurance’: '10', 'transit’: '13.8', 'final_res': '10.5'}"
9H-DGM    "{'departure’: '16’, 'endurance’: '10', 'transit’: '13.8', 'final_res': '10.5'}"
9H-DGN    "{'departure’: '16’, 'endurance’: '10', 'transit’: '13.8', 'final_res': '10.5'}"
G-DJET    "{'departure’: '14’, 'endurance’: '7.3', 'transit’: '10.4', 'final_res': '9'}"
G-ZDEA    "{'departure’: '14’, 'endurance’: '7.3', 'transit’: '10.4', 'final_res': '9'}"
G-ZATG    "{'departure’: '14’, 'endurance’: '7.3', 'transit’: '10.4', 'final_res': '9'}"
9H-IKY    "{'departure’: '14’, 'endurance’: '7.3', 'transit’: '10.4', 'final_res': '9'}"
G-YDEA    "{'departure’: '14’, 'endurance’: '8.0', 'transit’: '11.6', 'final_res': '9.5'}"
G-EMPP    "{'departure’: '14’, 'endurance’: '8.8', 'transit’: '12', 'final_res': '9'}"
G-DMNG    "{'departure’: '14’, 'endurance’: '8.8', 'transit’: '12', 'final_res': '9'}"
G-WKTG    "{'departure’: '14’, 'endurance’: '8.8', 'transit’: '12', 'final_res': '9'}"
9H-DGB    "{'departure’: '14’, 'endurance’: '8.8', 'transit’: '12', 'final_res': '9'}"
G-WKTO    "{'departure’: '600’, 'endurance’: '400', 'transit’: '500', 'final_res': '300’}"
G-WKTS    "{'departure’: '600’, 'endurance’: '400', 'transit’: '500', 'final_res': '300’}"
G-WKTL    "{'departure’: '800’, 'endurance’: '550', 'transit’: '650', 'final_res': '400’}"
2-WKTN    "{'departure’: '800’, 'endurance’: '550', 'transit’: '650', 'final_res': '400’}"
G-WKTK    "{'departure’: '800’, 'endurance’: '550', 'transit’: '650', 'final_res': '400’}"
P-HZHZ    "{'departure’: '800’, 'endurance’: '550', 'transit’: '650', 'final_res': '400’}"
G-RTNA    "{'departure’: '700’, 'endurance’: '650', 'transit’: '750', 'final_res': '450’}"
2-WKTJ    "{'departure’: '700’, 'endurance’: '610', 'transit’: '700', 'final_res': '450’}"

event.value = JSON.parse(this.getField("Name").value).departure
event.value = JSON.parse(this.getField("Name").value).endurance
event.value = JSON.parse(this.getField("Name").value).transit
event.value = JSON.parse(this.getField("Name").value).final_res

 

Where can I put this array? How would I call it in each cell?

Sorry if all this sounds very basic.. I just can't find any information online... 😞

People will choose "Aircraft Registration", and then choose the type of task. Once these two are set, then javascript should populate the EFO (Estimated fuel onboard) field each hour (starting from an amount set by the user and then subtracting the fuel flow per hour from said amount)...

Sorry if it's a bit confusing. I'm trying my best! 😄

I've attached the PDF here, so you can see...

Thanks in advance!!

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

Here is a script that does the basic thing you yare asking for: take two dropdowns and determine the output value. In the lastter part of your question, you throw a few more things in, but lets first talk about the basics. 

 

You have two dropdowns in yoru form (I called AirCraft and Power), and then a data structure that determines what the output should be for all cases. Here is the script that I would use as the calculation script for the output field:

 

var data = {
    "AirCraft1" : {
        "Max Speed" : "AC1 - max speed",
        "Max Range" : "AC1 - max range"
    },
    "AirCraft2" : {
        "Max Speed" : "AC2 - max speed",
        "Max Range" : "AC2 - max range"
    },
    "AirCraft3" : {
        "Max Speed" : "AC3 - max speed",
        "Max Range" : "AC3 - max range"
    }
}

// get the air craft field value
var aircraft = this.getField("AirCraft").value;
// get the power value
var power = this.getField("Power").value;

// do we have valid entry for both aircraft and power?
if (typeof data[aircraft] != "undefined" && typeof data[aircraft][power] != "undefined") {
    event.value = data[aircraft][power];
}

As you can see, I have the data right in the script. Ideally, I would store this in a document level script. When you add a document level script in Acrobat, it will give you an empty function stub. Remove all of that and replace it with this the data structure. You can then access this data from all scripts in this document. 

 

Does that make sense? 

1 reply

Karl Heinz  Kremer
Community Expert
Karl Heinz KremerCommunity ExpertCorrect answer
Community Expert
April 21, 2023

Here is a script that does the basic thing you yare asking for: take two dropdowns and determine the output value. In the lastter part of your question, you throw a few more things in, but lets first talk about the basics. 

 

You have two dropdowns in yoru form (I called AirCraft and Power), and then a data structure that determines what the output should be for all cases. Here is the script that I would use as the calculation script for the output field:

 

var data = {
    "AirCraft1" : {
        "Max Speed" : "AC1 - max speed",
        "Max Range" : "AC1 - max range"
    },
    "AirCraft2" : {
        "Max Speed" : "AC2 - max speed",
        "Max Range" : "AC2 - max range"
    },
    "AirCraft3" : {
        "Max Speed" : "AC3 - max speed",
        "Max Range" : "AC3 - max range"
    }
}

// get the air craft field value
var aircraft = this.getField("AirCraft").value;
// get the power value
var power = this.getField("Power").value;

// do we have valid entry for both aircraft and power?
if (typeof data[aircraft] != "undefined" && typeof data[aircraft][power] != "undefined") {
    event.value = data[aircraft][power];
}

As you can see, I have the data right in the script. Ideally, I would store this in a document level script. When you add a document level script in Acrobat, it will give you an empty function stub. Remove all of that and replace it with this the data structure. You can then access this data from all scripts in this document. 

 

Does that make sense? 

Ralph5C9EAuthor
Participant
April 25, 2023

Hi Karl,
Thank you for your reply! So, I need to add the above to every empty cell that needs to have a value depending on the output of both drop down menus?

I'll give it a try and let you know! 🙂

try67
Community Expert
Community Expert
April 25, 2023

No, you should only declare the data model once, in a doc-level script, then refer to it in a script from each field. Otherwise, if you wanted to change something in it later on you would have to edit all copies of it, which would be a huge waste of time.