Dependant menus in php using java script method?
<p>I am work on HTML and PHP on my project , but I have a problem :</p>

<p>I have a drop down list with countries and I want a nother drop down list to appear with (cities of this country) when user choose a country  </p>

<p>I have the countries data base and cities data base ( sql )</p>

<p>I try to use a java script method to do that but it didnt work</p>

<p>this is my code </p>

<p>First : this is the countries drop down list it is work good :</p>

<pre><code>&lt;select name="SelectCountry"  id="SelectCountry" onchange="showCity()" &gt;
            &lt;?php 
            $Con= mysql_connect("localhost","root",""); 
if(!$Con) { die('Could not connect'.mysql_error());}
if(!mysql_selectdb("MyDB",$Con)){die(mysql_error());}
$sql = "SELECT *  FROM countries";
$result = mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result)){
       echo ("&lt;option value=\"".$row['CountryID']."\"&gt;".$row['Name']."&lt;/option&gt;");

}
mysql_close($Con);
</code></pre>

<p>Second , this is the java script function showCity() // <strong>didnt work any way !!</strong></p>

<pre><code>&lt;script&gt;
             function showCity()
{

alert("in the function !!");  

Document.write(" &lt;?php echo "&lt;select 'SelectCity' ,'SelectCity'";
            echo "&lt;/select&gt;";
            $theCountry=$_GET['SelectCountry'];  // get the country ID
            $Con= mysql_connect("localhost","root",""); 
if(!$Con) { die('Could not connect'.mysql_error());}
if(!mysql_selectdb("MyDB",$Con)){die(mysql_error());}
$sql = "SELECT * FROM cities WHERE  cities.Fips=(SELECT Fips FROM countries WHERE CountryID='$theCountry')"; // retrive the cities for the spicific country (work when I enter the ID manully in the sql query e.g CountryID='43')

$result = mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result)){
       echo ("&lt;option value=\"".$row['Fips']."\"&gt;".$row['Fullname']."&lt;/option&gt;"); // print all the cities in a menu (work when I enter the ID manully in the sql query e.g CountryID='43') 
}
mysql_close($Con);
             ");"; ?&gt; ");
}
&lt;/script&gt;
</code></pre>

<p>this method is to create a new dropdown list for the spicific country cities when the user change the country by using <strong>Onchange</strong> Event</p>

<p>I hope you will help me</p>

<p>if there any Questions or misanderstod I am ready to answer or explain</p>

<p>thaaaanks all :)</p>
