Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

looping through a 3D array to populate 3 dependent dropdowns

Avatar

Former Community Member
I have a subform with 3 dependent dropdowns that I am trying to populate with a 3d array. I have tried to adapt the code from the Purchase Order example that came with LiveCycle Designer. My array is as follows:



var chooseFR = [[["California"],

["Apples","Bugs","Fungus"],

["Asparagus", "Mites", "Weeds"],

["Berries", "Fungus","Mites"]],

[["Arizona"],

["Citrus","Bugs", "Weeds"],

["Cole Crops", "Mites", "Weeds"]]];



I would like to have the first dropdown populated with the state, the second with the crops specified in each state, and the third with the pests associated with the specified state/crop combo.



This is the function that populates the first dropdown, which is called at initialization of the form:



function getState(dropdownField)

{

dropdownField.clearItems();

for (var i=0; i < chooseFR.length; i++)

dropdownField.addItem(chooseFR[i][0][0]);

}



Here is the function to populate the second dropdown, which is called at initialization:



function getCrop(cropField, dropdownField)

{

dropdownField.clearItems();

for (var i=0; i < chooseFR.length; i++)

if(chooseFR[i][0] == cropField.rawValue)

{

for (var j=1; j < chooseFR.length; j++)

{

dropdownField.addItem(chooseFR[i][j]);

}

}

}



Here is the script for the second dropdown for a change event with the first dropdown:



function getStatesOther(myXfa, dropdownField)

{

dropdownField.clearItems();

for (var i=0; i < chooseFR.length; i++)

if(chooseFR[i][0] == myXfa.event.newText)

{

for (var j=1; j < chooseFR[i].length; j++)

{

dropdownField.addItem(chooseFR[i][j]);

}

}

}



What is happening when I click on the second dropdown, is that for California, I get a dropdown populated with three instances of "Empty", and for Arizona I get two instances of "Empty", that's how I know that the change script is working. I am hoping that once I get the second dropdown working, the script for the third will be similarly structured.
0 Replies