he handler gets called when the parent selector's value is chosen,
// which generates a "change" event...the handler is attached to that event
parent_select.on( 'change', function() {
// hide any child options that were made visible before
clear_child();
// identify the group that was selected
var selection = $(this).find('option:selected').text();
// find the corresponding optgroup in the child selector
var child_group = child_select.find('optgroup[label*="'+selection+'"]');
// make that one optgroup visible
child_group.css('display','inherit');
// if the child's value is in a visible optgroup, select it
if ( child_select.find('option[value="' + child_value + '"]').is(':visible')) {
child_select.val(child_value);
}
});
// now that everyting is defined, set our initial condition by triggering a state change in the parent selector
grandparent_select.trigger('change');
// now that everyting is defined, set our initial condition by triggering a state change in the parent selector
parent_select.trigger('change');
});