I'm trying to make a fairly advanced hierarchy of drop down options. I'm attempting to make it so any options that aren't related to the previous option chosen, will be hidden. For an example, when Device Groups is chosen, the second dropdown will be "Group Details" (from the middle dropdown) by default, and the bottom dropdown will disappear since it wont be used. Then when I switch back to Device Settings (top dropdown) the middle dropdown will default to Device Details (middle dropdown) and the bottom dropdown will reappear and only show options related to Device and not Notification.
Here's my code,
/* global $ */
$(document).ready(function(){
$( "#top" ).change(function() {
var value = $(this).val();
$("#middle").prop("disabled", false);
$("#middle > option").hide();
$("#middle > option[value*='" + value +"']").show();
$("#bottom").prop("disabled", false);
$("#bottom > option").hide();
$("#bottom > option[value*='" + value +"']").show();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<select id="top" class="top">
<option value="Settings">Device Settings</option>
<option value="Groups">Device Groups</option>
</select>
<br /><br />
<select id="middle" class="middle">
<option value="Settings--Details">Device Details</option>
<option value="Settings--Notification">Notification List</option>
<option value="Settings--Digital">Digital Inputs</option>
<option value="Settings--Analog">Analog Inputs</option>
<option value="Settings--DigitalO">Digital Outputs</option>
<option value="Settings--Geofencing">Geofencing</option>
<option value="Settings--Application">Application Specific</option>
<option value="Groups--GroupDe">Group Details</option>
</select>
<br /><br />
<select id="bottom" class="bottom">
<option value="Settings--Details--BasicInfo">Basic Info</option>
<option value="Settings--Details--SiteDetails">Site Details</option>
<option value="Settings--Notification--Add">Add or Edit</option>
<option value="Settings--Notification--Import">Import Notification List</option>
<option value="Settings--Digital--Displayed">Show Displayed Only</option>
<option value="Settings--Digital--All">Show All</option>
</select>
</div>