title: updating a select drop down (html) with sql information
body: <p>I am really confused. I want to create a Select drop down menu using information from an sql database. everything works out great but i have one question. how do i update the select drop down every time the user changes his selection. the question is really confusing and i dont really know how to describe it.. I set up the code in php and then put it inside my page. here is the code:</p>
  <pre><code>&lt;?php
  //creating a function to generate the second select menu
  function createNameSelect(){
      $options = &quot;&lt;select id='name'&gt;&quot;
      $sql = &quot;SELECT * FROM names WHERE category = 'c'&quot;;
      $result = mysql_query($sql);
  
      $options.=&quot;&lt;option value='nothing'&gt;-- select an option --&lt;/option&gt;&quot;;
  
      while ($row=mysql_fetch_array($result)){
          $name=$row['name'];
          $options.=&quot;&lt;option value='$name'&gt;$name&lt;/option&gt;&quot;;
      }
  
      $options.=&quot;&lt;/select&gt;&quot;;
  
      return &quot;$options&quot;;
  }
  ?&gt;
  
  
  
  &lt;!DOCTYPE html&gt;
  ....
  &lt;select id = c&gt;
     &lt;option value ='1'&gt;option 1&lt;/option&gt;
     &lt;option value ='2'&gt;option 2&lt;/option&gt;
     &lt;option value ='3'&gt;option 3&lt;/option&gt;
  &lt;/select&gt;
   &lt;?php createNameSelect(); ?&gt;
  
  ....
  &lt;/html&gt;
  </code></pre>
  <p>now, it works perfect, however, it won't update the select menu that follows the first one.
  it would be stuck on the menu generated from the default option.
  any idea what i can do to fix it? is there a js solution to it?</p>
  <p>Thanks!</p>