I would like to dynamically change the options of a HTML dropdown menu based on which company a user selects - for example, I have this JSON data:
series: [
{name: 'Company A', product: 'A1'},
{name: 'Company A', product: 'A2'},
{name: 'Company A', product: 'A3',},
{name: 'Company B', product: 'B1'},
{name: 'Company B', product: 'B2'}
]
And I have two dropdown menus:
<div class="col-md-4" >
<select class="company">
<option value=''><strong>Name</strong></option>
<option value="Company A">Company A</option>
<option value="Company B">Company B</option>
</select>
</div>
If the user selects Company A, then my 2nd dropdown will show products for that company:
<div class="col-md-4" >
<select class="product">
<option value=''><strong>Products</strong></option>
<option value="A1">A1</option>
<option value="A2">A2</option>
<option value="A3">A3</option>
</select>
</div>
Likewise, if the user selects Company B, the options will be B1, B2.
I am stuck with a function similar to this one (I am new to web dev and an largely unfamiliar with javascript and its syntax):
$('.company').change(function() {
company = this.value;
if (company) {
Highcharts.each(chart.series, function(ob, j) {
if (...................) {
ob.setVisible(true, true)
} else {
ob.setVisible(false, false)
}
});
}
})
This function relates to the Highcharts API, but I don't think that that is relevant to the question; I am looking for a more general JQuery/JavaScript answer, it doesn't have to entail Highcharts...