I'm starting to create “drill” selection items (select items that filter their settings based on the previous settings you selected.

Being that I have never done this before, I am looking for a “best practical” approach to this general situation. Could you point me to a tutorial or provide some sample code, how should I approach this?
Decision
I initially thought about hiding and showing options, but it turns out that the approach is not compatible with a cross browser. The simplest, cross-browser method I've come across is creating a copy of the original selection options and replacing the parameters after the user made the selection. I wrote a small jQuery plugin that makes it somewhat more reusable.
<select id="first"> <option value="1">Fruits</option> <option value="2">Vegetables</option> </select> <select id="second"> <option> -- Select -- </option> <option class="first_1" value="1">Apple</option> <option class="first_1" value="2">Orange</option> <option class="first_1" value="3">Banana</option> <option class="first_2" value="4">Carrot</option> <option class="first_2" value="5">Broccoli</option> <option class="first_2" value="6">Spinach</option> </select> <script type="text/javascript"> $.fn.drilldown = function(child) { var $parent = this; var parentId = $parent.attr('id'); var $child = $(child); var childId = $child.attr('id'); var optionIdentifier = '.' + parentId + '_'; var selectedChildOption = $child.val(); var $childCopy = $('<select id='+parentId+childId+' />'); $childCopy.html($child.find('option')).hide().appendTo('body'); var refreshOptions = function(){ var selectedParentValue = $parent.val(); $child.html($childCopy.find(optionIdentifier+selectedParentValue).clone()); $child.prepend('<option value="0" selected="selected"> -- Select -- </option>'); }; refreshOptions(); $child.val(selectedChildOption); $parent.change(function(){ refreshOptions(); $child.trigger('change').focus(); }); }; $(document).ready(function(){ $('#first').drilldown('#second'); }); </script>
Here is jsFiddle to show that it works.
source share