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

Generating a Dropdown Options from two previous Dropdowns

New Here ,
Feb 10, 2025 Feb 10, 2025

I'm trying to have the option from Dropdown1 and the Dropdown2 generate a new set of options that populate Dropdown3. So, if someone selected Option 1 in Dropbox 1 and Option3 in Dropbox2, the options available in Dropbox3 would be ItemA, ItemB, ItemC, Item D, ItemE, ItemK, ItemL, ItemM, ItemN, and ItemO from which they could choose one. Whats happening is, whichever Dropbox1 or Dropbox2 I click on most recently is populating with its selections and deleting the previous ones. I need all 10 to populate. 

 

The code I am currently using in Dropbox1's "Dropdown Properties - Validate - Run custom validation script":

var f = this.getField("Dropdown3");
switch(event.value){
case "Option1":
f.setItems(["ItemA", "ItemB", "ItemC", "ItemD", "ItemE"]);
break;
case "Option2":
f.setItems(["ItemF", "ItemG", "ItemH", "ItemI", "ItemJ"]);
break;
default:
f.setItems([""]);
}

 

The code I am currently using in Dropbox2's "Dropdown Properties - Validate - Run custom validation script":

var f = this.getField("Dropdown3");
switch(event.value){
case "Option3":
f.setItems(["ItemK", "ItemL", "ItemM", "ItemN", "ItemO"]);
break;
case "Option4":
f.setItems(["ItemP", "ItemQ", "ItemR", "ItemS", "ItemT"]);
break;
default:
f.setItems([""]);
}

TOPICS
JavaScript , PDF , PDF forms
444
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Feb 10, 2025 Feb 10, 2025

Remove both scripts and use this as 'Custom calculation script' of "Dropdown3" field:

var options = {
 "Option1": ["ItemA", "ItemB", "ItemC", "ItemD", "ItemE"],
 "Option2": ["ItemF", "ItemG", "ItemH", "ItemI", "ItemJ"],
 "Option3": ["ItemK", "ItemL", "ItemM", "ItemN", "ItemO"],
 "Option4": ["ItemP", "ItemQ", "ItemR", "ItemS", "ItemT"]
};

var d1 = this.getField("Dropdown1").valueAsString;
var d2 = this.getField("Dropdown2").valueAsString;

if (event.source && (event.source.name == "Dropdown1" || event.source.name == "Dropdown2")) {
 var dropSelections = [];

if (options[d1] && options[d2]) {  
 dropSelections = (d1 === d2) ? options[d1] : options[d1].concat(options[d2]);}
 
 if(dropSelections.length > 0){
  event.target.setItems(dropSelections);}
 else{
 event.target.clearItems();}}

This should cover all possible combinations.

View solution in original post

Translate
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 10, 2025 Feb 10, 2025

Enter the following validation script in Dropdown1:

 

var op1=["ItemA", "ItemB", "ItemC", "ItemD", "ItemE"];
var op2=["ItemF", "ItemG", "ItemH", "ItemI", "ItemJ"];
var op3=["ItemK", "ItemL", "ItemM", "ItemN", "ItemO"];
var op4=["ItemP", "ItemQ", "ItemR", "ItemS", "ItemT"];
var newList=[""];

if(event.value=="Option1")
{newList=op1}
if(event.value=="Option2")
{newList=op2}

if(this.getField("Dropdown2").value=="Option3")
{
for(var i=0;i<op3.length;i++)
{newList.push(op3[i])}
}

if(this.getField("Dropdown2").value=="Option4")
{
for(var i=0;i<op4.length;i++)
{newList.push(op4[i])}
}

this.getField("Dropdown3").setItems(newList);

 

Enter the following validation script in Dropdown2:

 

var op1=["ItemA", "ItemB", "ItemC", "ItemD", "ItemE"];
var op2=["ItemF", "ItemG", "ItemH", "ItemI", "ItemJ"];
var op3=["ItemK", "ItemL", "ItemM", "ItemN", "ItemO"];
var op4=["ItemP", "ItemQ", "ItemR", "ItemS", "ItemT"];
var newList=[""];

if(this.getField("Dropdown1").value=="Option1")
{newList=op1}

if(this.getField("Dropdown1").value=="Option2")
{newList=op2}

if(event.value=="Option3")
{
for(var i=0;i<op3.length;i++)
{newList.push(op3[i])}
}
if(event.value=="Option4")
{
for(var i=0;i<op4.length;i++)
{newList.push(op4[i])}
}

this.getField("Dropdown3").setItems(newList);

 

Translate
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 10, 2025 Feb 10, 2025

Remove both scripts and use this as 'Custom calculation script' of "Dropdown3" field:

var options = {
 "Option1": ["ItemA", "ItemB", "ItemC", "ItemD", "ItemE"],
 "Option2": ["ItemF", "ItemG", "ItemH", "ItemI", "ItemJ"],
 "Option3": ["ItemK", "ItemL", "ItemM", "ItemN", "ItemO"],
 "Option4": ["ItemP", "ItemQ", "ItemR", "ItemS", "ItemT"]
};

var d1 = this.getField("Dropdown1").valueAsString;
var d2 = this.getField("Dropdown2").valueAsString;

if (event.source && (event.source.name == "Dropdown1" || event.source.name == "Dropdown2")) {
 var dropSelections = [];

if (options[d1] && options[d2]) {  
 dropSelections = (d1 === d2) ? options[d1] : options[d1].concat(options[d2]);}
 
 if(dropSelections.length > 0){
  event.target.setItems(dropSelections);}
 else{
 event.target.clearItems();}}

This should cover all possible combinations.

Translate
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 11, 2025 Feb 11, 2025
LATEST

Thanks so much, that worked like a charm.

Translate
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