title: Chained ajax Select Boxes
body: <p>I have some problems with my html/php/ajax code about dependent (or chained) select. I want to show in my menu the list of faculties after I have decided the university.
  I'll show you my (italian) code. I hope you'll help me. Thanks.</p>
  
  <p>javascript ajax code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  $(document).ready(function()
  {
  
  $(".universita").change(function()
  {
  var dataString = 'id='+ $(this).val();
  $.ajax
  ({
  type: "POST",
  url: "ajax_facolta.php",
  data: dataString,
  cache: false,
  success: function(html)
  {
  $(".facolta").html(html);
  } 
  });
  
  }); 
  
  });
  </code></pre>
  
  <p></p>
  
  <p>html code about two select boxes:</p>
  
  <pre><code>&lt;td align="right"&gt;Università:   &lt;/td&gt;
      &lt;td&gt;
      &lt;select class="input" name="universita"&gt;
          &lt;option selected="selected"&gt;--Seleziona Università--&lt;/option&gt;
      &lt;?php 
  
          require('config.php');
  
          $query = mysqli_query($con, "SELECT * FROM UNIVERSITA order by id ASC");
  
          $num_righe = mysqli_num_rows($query);
  
          for($x=0; $x&lt;$num_righe; $x++)
              {
              $rs = mysqli_fetch_row($query);
                              $id = $rs[0];
              $nome = $rs[1];
      ?&gt;
              &lt;option value="&lt;?php echo $id;?&gt;"&gt; &lt;?php echo $nome; ?&gt;&lt;/option&gt;
      &lt;?php
              }
      ?&gt;
      &lt;/select&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td align="right"&gt;Facoltà: &lt;/td&gt;
      &lt;td&gt;&lt;select class="input" name="facolta"&gt;
              &lt;option selected="selected"&gt;--Seleziona Facoltà--&lt;/option&gt;
          &lt;/select&gt;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>the file ajax_facolta.php:</p>
  
  <pre><code>&lt;?php
  
  require('config.php');
  
  if($_POST['id'])
  {
      $id=$_POST['id'];
      $sql = mysqli_query($con, "SELECT * FROM FACOLTA WHERE id_univ='$id' ");
  
      echo '&lt;option selected="selected"&gt;--Selziona Facoltà--&lt;/option&gt;';
  
      while($row=mysqli_fetch_array($sql))
          {
  
          $id=$row['id'];
          $nome=$row['nome'];
          echo '&lt;option value="'.$id.'"&gt;'.$nome.'&lt;/option&gt;';
          }
  
  }
  </code></pre>
  
  <p>?></p>
  
  <p>and the simple configure.php:</p>
  
  <pre><code>&lt;?php
  
  $con = mysqli_connect("127.6.143.130","xxxxx","xxxxx", "jeme");
  
  if (!$con)
    {
    die('Errore nella connessione: ' . mysqli_connect_error());
    }
  </code></pre>
  
  <p>?></p>
  
  <p>The database is very simple.
  UNIVERSITA has (id, nome)
  FACOLTA has (id, nome, id_univ).
  I do not find any errors but it does not work. Thanks for the help.</p>