Input of a box to determine the displayed options of a second input box

I am trying to have the input of one box determine the dispalyed options of a second input box, i.e if you select district "one" in the "district" box (Districtbox) then it will only display projects A, B and C as selectable options in the "project" box. This is my JS code but the resultingProject returns an empty output even if const inputDistrict = 'One' or const inputDistrict = Districtbox.value

  // Given project and district pairs
const projectDistrictPairs = [
  { project: 'A', district: 'One' },
  { project: 'B', district: 'One' },
  { project: 'C', district: 'One' },
  { project: 'D', district: 'Two' },
  { project: 'E', district: 'Three' },
  { project: 'F', district: 'Four' }
];

// Assuming you have an input variable named 'inputDistrict' that holds the input district value
const inputDistrict = 'One';

// Find the resulting project for the selected district
const resultingProject = projectDistrictPairs.find(pair => pair.district === inputDistrict)?.project;

console.log(resultingProject);

Hey Hugh!

Does this code work for you?

 // Given project and district pairs
const projectDistrictPairs = [
  { project: 'A', district: 'One' },
  { project: 'B', district: 'One' },
  { project: 'C', district: 'One' },
  { project: 'D', district: 'Two' },
  { project: 'E', district: 'Three' },
  { project: 'F', district: 'Four' }
];

return projectDistrictPairs.filter(pair=>pair.district=={{select1.value}}).map(pair=>pair.project)

1 Like

Hey stefancvrkotic,

I tried your code but I am getting the error:

message:"Unexpected token '{'"

When I try to run this code, I also tried removing the curly braces and that didn't work either. select1 is my input field for the project box but it does not show the project options for "One" for example, when "One" is in the district box

Any advice? Has this worked for you with the boxes?

Thanks,
Hugh

Hey stefancvrkotic,

Nevermind! I was using a JS query instead of a transformer, now it's working, thank you!

Best,
H