title: Populate Dropdown list depending on another Dropdown selection using Ajax
body: <p>I need to select an id depending on another id.
  I made by myself something but it is not working, so I am posting the CODE, maybe i have something wrong in it. Select the first option a vehicle, and in the second option select a model of the vehicle that I selected.
  Thanks!</p>
  
  <pre><code>//The config file
  
  &lt;?php
  
  $host = 'localhost';         
  $utilizator = 'stud';         
  $parola = 'stud';         
  $numebd = 'autodealer';      
  
  $conn = mysql_connect($host, $utilizator, $parola);
  if (!$conn) { echo '&lt;h4&gt;Connected!&lt;/h4&gt;'; }
  
  if (!mysql_select_db($numebd, $conn)) { 
     echo '&lt;h4&gt;Couldnt connect database : '. mysql_errno(). ' : '. mysql_error().'&lt;/h4&gt;'; 
  }
  
  mysql_set_charset('utf8', $conn);
  ?&gt;
  
  
  //The HTML code
  
  &lt;h2&gt;&lt;strong&gt;Vehicle&lt;/strong&gt; data&lt;/h2&gt;
      &lt;div class="select_wrapper"&gt;
      &lt;form action="" method="post" name="anunt" id="f_anunt"&gt;
          &lt;label&gt;&lt;span&gt;* &lt;/span&gt;&lt;strong&gt;Manufacturer:&lt;/strong&gt;&lt;/label&gt;
          &lt;select class="select_5" name="marca" id="marca"&gt;                           
              &lt;?php
                  $result = mysql_query("SELECT id_marca, denumire FROM marci ORDER BY ordine");
                  while($row = mysql_fetch_array($result)) {
                      echo ("&lt;option value='".$row['id_marca']."'&gt;".$row['denumire']."&lt;/option&gt;");
                  }
              ?&gt;
          &lt;/select&gt;
          &lt;/div&gt;
          &lt;div class="select_wrapper"&gt;
          &lt;label&gt;&lt;span&gt;* &lt;/span&gt;&lt;strong&gt;Model: &lt;/strong&gt;&lt;/label&gt;
              &lt;select class="select_5" name="model" id="model"&gt;
                  &lt;?php                                   
                      $result = mysql_query("SELECT id_model, denumire FROM modele WHERE id_marca=1");
                      while ($row = mysql_fetch_array($result)) {
                          echo ("&lt;option value='".$row['id_model']."'&gt;".$row['denumire']."&lt;/option&gt;");
                      }
                  ?&gt;
              &lt;/select&gt;
          &lt;/div&gt;
  
  //The PHP file
  
  &lt;?php
  include_once("config.php");
  
  $id_marca = $_POST['id_marca'];
  
  $sir_sql="SELECT id_model, denumire FROM modele WHERE id_marca=$id_marca ";
  
  if ($conn())
      {               
          $result=mysql_query($sir_sql,$conn);
  
          while ($row = mysql_fetch_array($result))       
             echo ("&lt;option value='".$row['id_model']."'&gt;".$row['denumire']."&lt;/option&gt;");
  
      }
      else 
          die('Comanda incorecta:&lt;br&gt; ' . mysql_error()); 
  ?&gt;
  
  //The Javascript code
  
  $("#marca").change(get_model);
  
      function get_model(e)
  {
      $.post("ajax_get_model.php",{id_marca:$(this).val()},function(data,status)
          {   
              $("#model").html(data); // pun modelele 
          });
  }
  </code></pre>