title: Filter Dropdown Based on Another Dropdown Selection
body: <p>I have multiple dropdowns and want to filter the contents of the second dropdown based on what is selected in the first dropdown. Here is the following code that I have so far. How could I do this?</p>
  
  <p>HTML/PHP:</p>
  
  <pre><code>&lt;td&gt;                        
      &lt;select id="major" onChange="updateCat();"&gt;
          &lt;?php foreach ($dropdown_major-&gt;fetchAll() as $drop_major): ?&gt;
                  &lt;option
                      value=""
                      data-name="&lt;?php echo $drop_major ['Major Category'];?&gt;"
                  &gt;
                      &lt;?php echo $drop_major ['Major Category'];?&gt;
                  &lt;/option&gt;
          &lt;?php endforeach; ?&gt;
      &lt;/select&gt;
  &lt;/td&gt;
  
  
  &lt;td&gt;
      &lt;select id="minor"&gt;
          &lt;?php foreach ($dropdown_minor-&gt;fetchAll() as $drop_minor): ?&gt;
                  &lt;option
                      value=""
                      data-name="&lt;?php echo $drop_minor ['Minor Category'];?&gt;"
                  &gt;
                      &lt;?php echo $drop_minor ['Minor Category'];?&gt;
                  &lt;/option&gt;
          &lt;?php endforeach; ?&gt;
      &lt;/select&gt;
  &lt;/td&gt;
  </code></pre>
  
  <p>JavaScript:</p>
  
  <pre><code>function updateCat() {
      var e = document.getElementById("major");
      var majorSelected = e.options[e.selectedIndex];
  
      document.getElementById("minor").value = majorSelected.dataset.name;
  }
  </code></pre>
  
  <p>Database connection and SQL statements:</p>
  
  <pre><code>&lt;?php
  $host="xxxxxxxxxxx"; 
  $dbName="xxxxx"; 
  $dbUser="xxxxxxxxxxxxx"; 
  $dbPass="xxxxxxxx";
  
  
  $dbh = new PDO( "sqlsrv:server=".$host."; Database=".$dbName, $dbUser, $dbPass);
  $dbh-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  $sql_major = "SELECT DISTINCT [Major Category] FROM ProductTable ORDER BY [Major Category] ASC";
  $sql_minor = "SELECT DISTINCT [Minor Category] FROM ProductTable ORDER BY [Minor Category] ASC";
  
  $dropdown_major = $dbh-&gt;query($sql_major);
  $dropdown_minor = $dbh-&gt;query($sql_minor);
  ?&gt;
  </code></pre>