==============Code for Country_State_City==============
<html>
<head>
<title> Country_State_City </title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function()
{
$('#id_con').on('change',function()
{
var id_con = $(this).val();
if(id_con)
{
$.ajax(
{
type:'POST',
url:'get_country.php',
data:'id_con=' + id_con,
success:function(html)
{
$('#id_state').html('<option> ==Select State== </option>'+html);
}
});
}
else
{
$('#id_state').html(
'<option value=""> select Country </option>'
);
}
});
$('#id_state').on('change',function()
{
var id_state = $(this).val();
if(id_state)
{
$.ajax(
{
type:'POST',
url:'get_country.php',
data:'id_state=' + id_state,
success:function(html)
{
$('#id_city').html('<option> ==Select Country== </option>'+html);
}
});
}
else
{
$('#id_city').html(
'<option value=""> select State </option>'
);
}
});
});
</script>
</head>
<body>
<center>
<form action="" method="POST">
<font size="3">
<table border="2">
<tr>
<?php
include('connection.php');
mysql_select_db('CSC');
?>
<td> Country: </td>
<td>
<select id="id_con" name="select_con">
<option> ==Select Country== </option>
<?php
$sql_con = mysql_query('select * from country;');
while($db_con = mysql_fetch_array($sql_con))
{
echo "<option value='$db_con[0]'>".$db_con[1]."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td> State: </td>
<td>
<select name="select_state" id="id_state">
<option> ==Select State== </option>
<option value="">
</option>
</select>
</td>
</tr>
<tr>
<td> City: </td>
<td>
<select name="select_city" id="id_city">
<option> ==Select City== </option>
<option value="">
</option>
</select>
</td>
</tr>
</table>
</font>
</form>
</center>
</body>
</html>
==============Code for get_country.php==============
<html>
<head>
<title> Country_State_City </title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function()
{
$('#id_con').on('change',function()
{
var id_con = $(this).val();
if(id_con)
{
$.ajax(
{
type:'POST',
url:'get_country.php',
data:'id_con=' + id_con,
success:function(html)
{
$('#id_state').html('<option> ==Select State== </option>'+html);
}
});
}
else
{
$('#id_state').html(
'<option value=""> select Country </option>'
);
}
});
$('#id_state').on('change',function()
{
var id_state = $(this).val();
if(id_state)
{
$.ajax(
{
type:'POST',
url:'get_country.php',
data:'id_state=' + id_state,
success:function(html)
{
$('#id_city').html('<option> ==Select Country== </option>'+html);
}
});
}
else
{
$('#id_city').html(
'<option value=""> select State </option>'
);
}
});
});
</script>
</head>
<body>
<center>
<form action="" method="POST">
<font size="3">
<table border="2">
<tr>
<?php
include('connection.php');
mysql_select_db('CSC');
?>
<td> Country: </td>
<td>
<select id="id_con" name="select_con">
<option> ==Select Country== </option>
<?php
$sql_con = mysql_query('select * from country;');
while($db_con = mysql_fetch_array($sql_con))
{
echo "<option value='$db_con[0]'>".$db_con[1]."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td> State: </td>
<td>
<select name="select_state" id="id_state">
<option> ==Select State== </option>
<option value="">
</option>
</select>
</td>
</tr>
<tr>
<td> City: </td>
<td>
<select name="select_city" id="id_city">
<option> ==Select City== </option>
<option value="">
</option>
</select>
</td>
</tr>
</table>
</font>
</form>
</center>
</body>
</html>
==============Code for get_country.php==============
<?php
include('connection.php');
mysql_select_db('CSC');
$id_con = $_REQUEST['id_con'];
$id_state = $_REQUEST['id_state'];
if($_REQUEST['id_con'])
{
$sql_con = mysql_query("select * from state where CoID='$id_con';");
while($db_con = mysql_fetch_array($sql_con))
{
echo "<option value='$db_con[0]'>".$db_con[2]."</option>";
}
}
else if($_REQUEST['id_state'])
{
$sql_state = mysql_query("select * from city where SID='$id_state';");
while($db_state = mysql_fetch_array($sql_state))
{
echo "<option value='$db_state[0]'>".$db_state[2]."</option>";
}
}
?>
include('connection.php');
mysql_select_db('CSC');
$id_con = $_REQUEST['id_con'];
$id_state = $_REQUEST['id_state'];
if($_REQUEST['id_con'])
{
$sql_con = mysql_query("select * from state where CoID='$id_con';");
while($db_con = mysql_fetch_array($sql_con))
{
echo "<option value='$db_con[0]'>".$db_con[2]."</option>";
}
}
else if($_REQUEST['id_state'])
{
$sql_state = mysql_query("select * from city where SID='$id_state';");
while($db_state = mysql_fetch_array($sql_state))
{
echo "<option value='$db_state[0]'>".$db_state[2]."</option>";
}
}
?>
Comments
Post a Comment