Skip to main content
Participant
July 24, 2023
Question

Multi-Condition Dropdowns

  • July 24, 2023
  • 1 reply
  • 467 views


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?

This topic has been closed for replies.

1 reply

Thom Parker
Community Expert
Community Expert
July 24, 2023

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

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
July 25, 2023

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?

Thom Parker
Community Expert
Community Expert
July 25, 2023

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. 

 

 

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