title: ajax php drop down list
body: <p>Can some one tell me what's wrong with this example code on this site <a href="http://www.x-developer.com/php-scripts/loading-drop-downs-with-ajax-php-and-fetching-values-from-database-without-refreshing-the-page" rel="nofollow">http://www.x-developer.com/php-scripts/loading-drop-downs-with-ajax-php-and-fetching-values-from-database-without-refreshing-the-page</a></p>
  
  <p>Basically i did exactly the same as in the turorial and the problem is that the 2nd drop down list is no showing anything. I read one of the comments that someone forgot to add in some javascript on the page. How do i do this?</p>
  
  <p>I have tried posting a question on that site but no one answered for a week now so I came here.</p>
  
  <p>Any help would be much appreciated.</p>
  
  <p>this is my index.php page</p>
  
  <pre><code>&lt;?php
  include('cn.php');
  
  $sql_country = "SELECT * FROM COUNTRY";
  $result_country = mysql_query($sql_country);
  
  echo "&lt;select name='country' onChange='get_cities(this.value)'&gt;"; //get_cities is defined below
  
  while($row_country = mysql_fetch_array($result_country))
  {
  echo "&lt;option value='".$row_country['id']."'&gt;".$row_country['country']."&lt;/option&gt;";
  }
  
  echo "&lt;/select&gt;";
  
  echo "&lt;select name='city' id='city'&gt;&lt;/select&gt;"; //We have given id to this dropdown
  
  ?&gt;
  </code></pre>
  
  <p>this is my get_cities.js page</p>
  
  <pre><code>function get_cities(country_id)
  {
  $.ajax({
     type: "POST",
     url: "cities.php", /* The country id will be sent to this file */
     beforeSend: function () {
    $("#city").html("&lt;option&gt;Loading ...&lt;/option&gt;");
      },
     data: "country_id="+country_id,
     success: function(msg){
       $("#city").html(msg);
     }
     });
   } 
  </code></pre>
  
  <p>This is my cities.php page</p>
  
  <pre><code>&lt;?php
  
  include('cn.php');
  
  // Code for cities.php
  $country_id = $_REQUEST['country_id'];
  
  $sql_city = "SELECT * FROM CITY WHERE country_id = '".$country_id."'";
  $result_city = mysql_query($sql_city);
  echo "&lt;select name='city'&gt;";
  
  while($row_city = mysql_fetch_array($result_city))
  {
  echo "&lt;option value='".$row_city['id']."'&gt;".$row_city['city']."&lt;/option&gt;";
  }
  
  echo "&lt;/select&gt;";
  
  ?&gt;
  </code></pre>
  
  <p>The included 'cn.php' is just my connection to the database.</p>