Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The ajax code is showing data of country state city from database but doesnt works in mozilla firefox
XML
<?php
  include("common.php");
  opendatabase();
  header("Cache-Control:no-cache,must-revalidate");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registration-Form</title>
</head>
<script type="text/javascript">
function showstate(str,ob)
{
var xmlhttp;
if (str.length==0)
  {
     if(ob==1)
     {

  document.getElementById("state1").innerHTML="";
     }
      if(ob==2)
     {
       document.getElementById("city1").innerHTML="";
     }
  return  str;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
         if(ob==1)
         {
        document.getElementById("state1").innerHTML=xmlhttp.responseText;
         }
         else
         {
            document.getElementById("city1").innerHTML=xmlhttp.responseText;
         }
      //alert(document.getElementById("state1").value);
      //alert(xmlhttp.responseText);
    }
  }
  if(ob==1)
  {
     xmlhttp.open("POST","state.php?countryid="+str,true);
  }
  else
  {
      xmlhttp.open("POST","city.php?stateid="+str,true);
  }
xmlhttp.send();
}
</script>
<body>
<form name="registration"  method="post"  action="registration.php?confirm=Y" autocomplete="off">
<?php
  if(!isset($_GET["confirm"]))
  {
    $_GET["confirm"]="";
  }
  $confirm=$_GET["confirm"];
   if($confirm!="Y")
   {
?>
<table align="center"><tr><td>Registration-Form</td></tr>
        </table>
        <table align="center">
        <tr><td>UserName</td>
        <td><input type="text" name="uname" /></td>
        </tr>
        <tr><td>Password</td>
            <td><input type="password" name="pwd" /></td>
        </tr>
        <tr><td>Address</td>
           <td><textarea name="address"></textarea>
           </td>
         </tr>
         <tr>
         <td>Email</td>
         <td><input type="text" name="email" />
         </td>
         </tr>
         <tr>
         <td>
         Mobile
         </td>
         <td><input type="text" name="mobile" /></td>
         </tr>
         <tr>
         <td>
         Country
         </td>
         <td><select name="country"  onchange="showstate(this.value,1);"  id="country1">
         <?php
           $sql="select  id,name from country";
           $query=mysql_query($sql) or die(mysql_error());
           $count=mysql_num_rows($query);
           if($count >=1)
           {
               echo "<option value=''>Select</option>";
               while($row=mysql_fetch_array($query))
               {
          ?>
           <option value="<?php echo $row['id'];?> "><?php echo $row['name']?></option>
          <?php
                }
           }
         ?>
         </select>
         </td>
         </tr>
         <tr>
         <td>
         State
         </td>
         <td><div id="state1">
        <select name="state">
         <option value=""></option>
         </select>
         </div>
         </td>
         </tr>
         <tr>
         <td>
         City
         </td>
         <td> <div id="city1">
         <select name="city">
         </select>
           </div>
         </td>
         </tr>
         <tr><td>PinCode</td>
         <td><input type="text" name="pincode" />
         </td>
         </tr>
         <tr><td></td>
         <td><input type="submit" name="submit" value="submit" />
         </td>
         </tr>
        <?php
         }
         else
         {
            //echo "$confirm";
            $uname=$_POST["uname"];
            $pwd=$_POST["pwd"];
            $address=$_POST["address"];
            $email=$_POST["email"];
            $mobile=$_POST["mobile"];
            $pincode=$_POST["pincode"];
         mysql_query("insert into signup(username,password,address,email,mobile,pincode) values('$uname','$pwd','$address','$email','$mobile','$pincode')") or die(mysql_error());
         echo "<center><b>User Registered Successfully</b></center>";
         }
        ?>
</form>
<?php
function  getstate()
{
}
?>
</body>
</html>

ow['id'];?> "><?php echo $row['name']?></option>
<?php
}
}
?>
</select>
</td>
</tr>
<tr>
<td>
State
</td>
<td><div id="state1">
<select name="state">
<option value=""></option>
</select>
</div>
</td>
</tr>
<tr>
<td>
City
</td>
<td> <div id="city1">
<select name="city">
</select>
</div>
</td>
</tr>
<tr><td>PinCode</td>
<td><input type="text" name="pincode" />
</td>
</tr>
<tr><td></td>
<td><input type="submit" name="submit" value="submit" />
</td>
</tr>
<?php
}
else
{
//echo "$confirm";
$uname=$_POST["uname"];
$pwd=$_POST["pwd"];
$address=$_POST["address"];
$email=$_POST["email"];
$mobile=$_POST["mobile"];
$pincode=$_POST["pincode"];
mysql_query("insert into signup(username,password,address,email,mobile,pincode) values('$uname','$pwd','$address','$email','$mobile','$pincode')") or die(mysql_error());
echo "<center><b>User Registered Successfully</b></center>";
}
?>
</form>
<?php
function getstate()
{
}
?>
</body>
</html>
Posted
Comments
thatraja 17-Jun-11 8:56am    
Check the error in firefox error console, include the error message in your question & let us know.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900