title: populating a dropdown box, based on the selection of another dropdown box using php, mqsql and ajax
body: <p>I am trying to populate a drop down box, based on a selection from another drop down box.  Here is what I have for php code:</p>
  
  <pre><code>&lt;form id="inventory" method="POST" action=""&gt;
     &lt;fieldset&gt;
        &lt;label for="area" &gt;Select Shelf Area&lt;/label&gt;
        &lt;select id="area" name="area"&gt;
            &lt;option value=""&gt;&lt;/option&gt;
  
            &lt;?php $area = $conn-&gt;query("
               select substring_index(location, ' ', 1) as area
               FROM location GROUP BY substring_index(location, ' ', 1)");
  
               while ($row = $area-&gt;fetch_assoc()) {
                  echo '&lt;option value="' . $row['area'] . '" &gt;' . $row['area'] . '&lt;/option&gt;';
               }
            &gt;
        &lt;/select&gt;&lt;br/&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;     
  </code></pre>
  
  <p>When I run my query, all is fine, but I need to take the results of this and use it to populate another drop down box ( the &lt;'value from previous drop down '>) which is here:</p>
  
  <pre><code>echo "&lt;label for='location' id='label'&gt;Select location:&lt;/label&gt;";
  echo "&lt;select id='location' name='location'&gt;";
  echo "&lt;option value=''&gt;--Select Location--&lt;/option&gt;";
  $query = "SELECT location_id, location FROM location
      WHERE location LIKE '&lt;value from previous drop down box&gt;'
      ORDER BY location";
  $result = $conn-&gt;query($query);
  while ($row = $result-&gt;fetch_assoc()) {
      echo '&lt;option value="' . $row['location'] . '" &gt;' . $row['location'] . '&lt;/option&gt;';
  }                                 
  </code></pre>
  
  <p>Any thoughts?
  Thanks
  Jim</p>