I've been grappling with this issue on and off for a few months now. Is it possible to incorporate the "OR" operator into the array structure below?
Here's the gist: If the value in a dropdown matches any of the values in the array, then the corresponding ID is passed to a function for further processing. However, I haven't been successful in implementing the OR operator.
For instance, I'd like to write something like:
{id : '418', value: 'Brochure' || 'Broc'},
{id : '546', value: 'Classified Ad' || 'CA' || 'Class Ad'},
But the above snippet never seems to work, leading me to question if it's even feasible or if my syntax is incorrect.
Any help or insights would be greatly appreciated.
Function executed upon finding a matching value
var projectTypes = [{
"id": "418",
"value": ["Brochure", "Broc"]
}, {
"id": "546",
"value": ["Classified Ad", "CA", "Class Ad"]
}, {
"id": "254",
"value": ["Flyer", "Flyers"]
}, {
"id": "855",
"value": "Post Card"
}];
function projectTypeChange() {
var project_type = document.getElementById(projectType_Field_Id).value;
SwitchBox(project_type);
}
function SwitchBox(selectedType) {
for (var i = 0; i < projectTypes.length; i++) {
if (projectTypes[i].value.indexOf(projectTypes) >= 0)
//if (projectTypes[i].value == selectedType)
{
document.getElementById("section-" + projectTypes[i].id).style.display = '';
} else {
document.getElementById("section-" + projectTypes[i].id).style.display = 'none';
}
}
}