Copy link to clipboard
Copied
I would like assistance for populating a different drop down based on two conditions. For example, I want to display rides in different sections of a theme park based on height level. I'd like to be able to filter on which section of the park as well as the height level to display the available options within that range? Is there a way to do this given that item 1 could potentially point to "south\>48in " as well as "south\<50in"?
Also where would I place the code for each conditional?
Copy link to clipboard
Copied
The answer is Yes! You can read about list/dropdown basics here:
https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm
Basically, use the "setItems" function to set the items in a dropdown. Use this function with care. It will change the value of the dropdown, and trigger calculations.
And the best way to handle changing a value based on multiple inputs is to use a calculation script.
https://www.pdfscripting.com/public/How-to-Write-a-Basic-PDF-Calculation-Script.cfm
https://www.pdfscripting.com/public/How-to-write-an-If-statement.cfm
Copy link to clipboard
Copied
Hello,
So I would need to create variables and calculations for each possibility? Would I have to assign each field and the corresponding values a variable as well?
Copy link to clipboard
Copied
You can create a single script to set the new items based on the values of the two input fields you've listed.
This can be done many different ways and the specifics depend on the specific requirements.
But Here's a very simple sample script that sets a different set of items based on the two inputs.
var cInputA = this.getField("FieldA").value;
var cInputB = this.getField("FieldB").value;
var aItemList = null;
if(cInputA == "Option1")
{
if(cInputB == "Choice1")
aItemList = ["A","B","C"];
else if(cInputB == "Choice2")
aItemList = ["AA","BB","CC"];
}
else if(cInputA == "Option2")
{
if(cInputB == "Choice1")
aItemList = ["a","b","c"];
else if(cInputB == "Choice2")
aItemList = ["aa","bb","cc"];
}
if(aItemList)
this.getField("Dropdown1").setItems(aItemList);
else
this.getField("Dropdown1").clearItems();
This code demonstrates a brute force decision pattern. You can use this in just about any situation.
Copy link to clipboard
Copied
If used as a calculation script, you won't be able to select items in the dropdown, so add this to the top of the script:
if (event.source && (event.source.name=="FieldA" || event.source.name=="FieldB")) {
And at the end of the script close curly bracket. Or use script at validate in both "FieldA" and "FieldB".