title: Multiple dependent dropdown menus
body: <p>I am stuck with multiple dynamic dropdowns. So here is the problem I try to solve. I have the following four example tables stored in a database and want to access the values dynamically. 
  Dropdown 2 is dependent on Dropdown 1, Dropdown 4 is dependent on 2 and 3. </p>
  
  <pre><code>| ID  | name   | percent |      | ID  | name    | languageValue | 100 | 75  | 501 |
  | --- | ------ | ------- |      | --- | ------- | ------------- | --- | --- | --- |
  | 1   | 100%   | 100     |      | 1   | English | english       | y   | y   | n   |
  | 3   | 75%    | 75      |      | 2   | German  | german        | y   | n   | n   |
  | 2   | 50% 1  | 501     |      | 3   | French  | french        | n   | n   | y   |
  Table 1 (Dropdown 1)            Table 2 (Dropdown 2)
  
  | ID  | CoreSubjectName | CoreSubjectValue |   | ID  | MinorSubjectName | MinorSubjectValue |
  | --- | --------------- | ---------------- |   | --- | ---------------- | ----------------- |
  | 1   | Maths           | maths            |   | 1   | English          | english           |
  | 2   | Politics        | politics         |   | 2   | Politics         | politics          |
  | 3   | Chemics         | chemics          |   | 3   | Chemics          | chemics           |
  Table 3 (Dropdown 3)                           Table 4 (Dropdown 4)
  </code></pre>
  
  <p>I retrieve the values for the first dropdown as the following. (I leave out the closing tags).</p>
  
  <pre><code>&lt;select name="percent" id ="percent" onchange="getPercent(this.value);"&gt;
      &lt;option value=""&gt;Choose Percent&lt;/option&gt;
  &lt;?php
     $PercentPost = $_POST["percent"];
     $PercentQuery = "SELECT percent, name FROM percentTable";
     $results=mysqli_query($conn, $anteilQuery);
     //loop
     while ($row = mysqli_fetch_array($results)){
         echo '&lt;option value="'.$row[percent].'"&gt;'.$row[name].'&lt;/option&gt;';
     }
  ?&gt;
  &lt;select name="language" id="language"&gt;
              &lt;option value=""&gt;&lt;/option&gt;
          &lt;/select&gt;
  </code></pre>
  
  <p>And the js-ajax for filling the second Dropdown:</p>
  
  <pre><code>function getPercent(val){
          //ajax function
          $.ajax({
              type: "POST",
              url: "form.php",
              data: "percent="+val,
              success: function(data){
                  $("#language").html(data);
              }
          });
  
      }
  </code></pre>
  
  <p>form.php contains this snippet so far:</p>
  
  <pre><code>$PercentPost = $_POST["percent"];
  if (!empty($_POST["percent"])) {
  
      $query="SELECT name, languageValue FROM table2 WHERE `$PercentPost`='y'";
  
      $results = mysqli_query($conn, $query);
  
      while ($row = mysqli_fetch_array($results)){
          echo '&lt;option value="'.$row[languageValue].'"&gt;'.$row[name].'&lt;/option&gt;';
      }
  }
  </code></pre>
  
  <p>This works fine, but now I don't know how to fill dropdown 4 dynamically. In Dropdown 4 the selected  values of 2 and 3 should not be selectable. I know it has to be done with ajax of js, but I have no clue how.</p>
  
  <p>Can someone help me out? 
  Thanx a lot!</p>