I am getting states from database on change of countries but not cities.
Here is the code:

<?php 
include("include/connection.php");

?>

<html>
<head><title>Contact Page</title>




<script type="text/javascript">
function AjaxFunction(cat_id)
{
var httpxml;
try
  {
  // Firefox, Opera 8.0+, Safari
  httpxml=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
          try
                    {
                 httpxml=new ActiveXObject("Msxml2.XMLHTTP");
                    }
            catch (e)
                    {
                try
            {
            httpxml=new ActiveXObject("Microsoft.XMLHTTP");
             }
                catch (e)
            {
            alert("Your browser does not support AJAX!");
            return false;
            }
            }
  }
function stateck() 
    {
    if(httpxml.readyState==4)
      {

var myarray=eval(httpxml.responseText);
// Before adding new we must remove previously loaded elements
for(j=document.testform.subcat.options.length-1;j>=0;j--)
{
document.testform.subcat.remove(j);

}
for(j=document.testform.subcat.options.length-1;j>=0;j--)
{
document.testform.subcat.remove(j);

}

for (i=0;i<myarray.length;i++)
{
var optn = document.createElement("OPTION");
optn.text = myarray[i];
optn.value = myarray[i];
document.testform.subcat.options.add(optn);


} 
for (i=0;i<myarray.length;i++)
{
var optn = document.createElement("OPTION");
optn.text = myarray[i];
optn.value = myarray[i];
document.testform.subcat.options.add(optn);

} 
      }
    }
    var url="dd.php";
url=url+"?cat_id="+cat_id;
url=url+"&sid="+Math.random();

httpxml.onreadystatechange=stateck;
httpxml.open("GET",url,true);
httpxml.send(null);
  }



  function AjaxFunction2(sid)
{
var httpxml;
try
  {
  // Firefox, Opera 8.0+, Safari
  httpxml=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
          try
                    {
                 httpxml=new ActiveXObject("Msxml2.XMLHTTP");
                    }
            catch (e)
                    {
                try
            {
            httpxml=new ActiveXObject("Microsoft.XMLHTTP");
             }
                catch (e)
            {
            alert("Your browser does not support AJAX!");
            return false;
            }
            }
  }
function stateck() 
    {
    if(httpxml.readyState==4)
      {

var myarray=eval(httpxml.responseText);
// Before adding new we must remove previously loaded elements
for(j=document.testform.subcity.options.length-1;j>=0;j--)
{
document.testform.subcity.remove(j);
}
for(j=document.testform.subcity.options.length-1;j>=0;j--)
{
document.testform.subcity.remove(j);
}

for (i=0;i<myarray.length;i++)
{
var optn = document.createElement("OPTION");
optn.text = myarray[i];
optn.value = myarray[i];
document.testform.subcity.options.add(optn);

} 
for (i=0;i<myarray.length;i++)
{
var optn = document.createElement("OPTION");
optn.text = myarray[i];
optn.value = myarray[i];
document.testform.subcity.options.add(optn);

} 
      }
    }
    var url="dd.php";
url=url+"?sid="+sid;
url=url+"&cid="+Math.random();
httpxml.onreadystatechange=stateck;
httpxml.open("GET",url,true);
httpxml.send(null);
  }

</script>

</head>
<body>
<form name="testform" id="testform" method='POST' action='contactmail.php'>
<div align="left">Name:<input type="text" name="uname"/><br>
Email:<input type="text" name="uemail"/><br>
Phone No:<input type="text" name="uphone"/><br>
<br><br><br><br>
Comments:<br><br><textarea type="text" name="ucomments"/></textarea><br><br>
<img src="CaptchaSecurityImages.php" /><br><br>
Security Code:
<input id="security_code" name="security_code" type="text" />
<br><br>

<table>
<tr>
<td style="text-align: left;">Country:</td>
<td style="text-align: left;">
<select name="cat_id" id="cat_id" onchange="AjaxFunction(this.value);">
<?php $result=mysql_query("select cat_id,country from country"); ?>
<option>Please Select Country</option>
<?php while($row=mysql_fetch_array($result))
{
    ?>

  <option value="<?=$row['cat_id']?>"><?=$row['country']?></option>

<?php  }?> 
</select>
</td>
</tr><tr>
<td style="text-align: left;">State:</td>
<td style="text-align: left;">




<select name="subcat" id="subcat" onchange="AjaxFunction2(this.value);">
<option>Please Select Coutry First</option>
</select>
</td>
</tr><tr>
<td style="text-align: left;">City:</td>
<td style="text-align: left;">

<select name="subcity"  id="subcity">
<option>Please Select State First</option>


</select>
</td>
</tr>
</table>
<br><input type="submit" name="consub" value="send"/><br>
<div align="center">

</form>
</div>
</div>


</body>
</html>

Can any one help me please. I'll be thankful to you

You might want to re-post the code using code-tags. It is difficult to make any sense of code posted the way you have done it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.