Nested dropdown lists : depending values
<p>I have two dropdown lists with values. When I select a value in the first, I want to return elements with the same selected value in the second. The second list depending of the first's list selection. How could I do this ?</p>

<pre><code>&lt;div class="form-group"&gt;
    &lt;label for="first"&gt;First list&lt;/label&gt;
        &lt;select id="first" class="form-control" role="listbox" onchange="filterList();"&gt;
            &lt;option value="Select level 1" selected="selected"&gt;Select...&lt;/option&gt;
            &lt;option value="Option 1"&gt;Option 1&lt;/option&gt;
            &lt;option value="Option 2"&gt;Option 2&lt;/option&gt;
        &lt;/select&gt;
&lt;/div&gt;
&lt;div class="form-group"&gt;
    &lt;label for="second"&gt;Second list&lt;/label&gt;
        &lt;select id="second" class="form-control" role="listbox"&gt;
            &lt;option value="Select level 2" data-group="Select" selected="selected"&gt;Select...&lt;/option&gt;
            &lt;option value="Option 1 - 1" data-group="Option 1"&gt;First list 1 - Element 1&lt;/option&gt;
            &lt;option value="Option 1 - 2" data-group="Option 1"&gt;First list 1 - Element 2&lt;/option&gt;
            &lt;option value="Option 2 - 1" data-group="Option 2"&gt;First list 2 - Element 1&lt;/option&gt;
            &lt;option value="Option 2 - 2" data-group="Option 2"&gt;First list 2 - Element 2&lt;/option&gt;
        &lt;/select&gt;
&lt;/div&gt;
</code></pre>

<p>jQuery script</p>

<pre><code>function filterList(){

    var first = $("#first").find('option:selected').text(); // stores first list selected elements

    $("#option-container").children().appendTo("#second"); // moves &lt;option&gt; contained in #option-container back to their &lt;select&gt;

    var toMove = $("#second").children("[data-group!='"+first+"']"); // selects elements to move out

    toMove.appendTo("#option-container"); // moves elements in #option-container

    $("#second").removeAttr("disabled"); // enables select
};
</code></pre>