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);
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?