Ajax Example
Screen shot
index.php

<?php
$con=mysql_connect('localhost','root','') or die('Mysql not connected');
mysql_select_db('test',$con) or die('DataBase not connected');
?>
<html>
<head>
<script type="text/javascript" src="ajax.js">
</script>
</head>
<body>
<form>
<select name="state" onChange= "display(this.value)">
<option value="" selected="selected">-- Select state --</option>
<?php
$query="select * from tbl_state";
$query_result=mysql_query($query)or mysql_error();
while($row=mysql_fetch_array($query_result))
{
?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['state_name']; ?></option>
<?php
}
?>
</select>
</form>
<br />
<div id="show_city">
<select name="city">
<option value="" selected="selected">-- Select city --</option>
</select>
</div>
</body>
</html>

show_city.php

<?php
$con=mysql_connect('localhost','root','') or die('Mysql not connected');
mysql_select_db('test',$con) or die('DataBase not connected');

$state_id=$_REQUEST['state_id'];

$query="select * from tbl_city where state_id='$state_id'";

?>
<select name="city">
<option value="" selected="selected">-- Select city --</option>
<?php
$query_result=mysql_query($query)or mysql_error();
while($row=mysql_fetch_array($query_result))
{
?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['city_name']; ?></option>
<?php
}
?>
</select>

ajax.js

// JavaScript Document
var XMLHttpRequestObject=false;
function display(state_id)
{
if(window.XMLHttpRequest)
{
XMLHttpRequestObject=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
XMLHttpRequestObject=new ActiveXObject("Microsoft.XMLHTTP");
}
XMLHttpRequestObject.onreadystatechange=function()
{
if (XMLHttpRequestObject.readyState==4 && XMLHttpRequestObject.status==200)
{
document.getElementById("show_city").innerHTML=XMLHttpRequestObject.responseText;
}
}
XMLHttpRequestObject.open("GET","show_city.php?state_id="+state_id,true);
XMLHttpRequestObject.send();
}

Database

--
-- Database: `test`
--

-- --------------------------------------------------------

--
-- Table structure for table `tbl_city`
--

CREATE TABLE IF NOT EXISTS `tbl_city` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `state_id` varchar(255) NOT NULL,
  `city_name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;

--
-- Dumping data for table `tbl_city`
--

INSERT INTO `tbl_city` (`id`, `state_id`, `city_name`) VALUES
(1, '1', 'New Delhi'),
(2, '2', 'Bareilly'),
(3, '2', 'Lucknow'),
(4, '2', 'Allahabad'),
(5, '2', 'Varanasi'),
(6, '2', 'Noida'),
(7, '3', 'Patna'),
(8, '3', 'Chhapra'),
(9, '3', 'Nalanda'),
(10, '3', 'Munger'),
(11, '3', 'begusarai'),
(12, '4', 'chandigarh'),
(13, '4', 'Ludhiana'),
(14, '4', 'Phagwara');

-- --------------------------------------------------------

--
-- Table structure for table `tbl_state`
--

CREATE TABLE IF NOT EXISTS `tbl_state` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `state_name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `tbl_state`
--

INSERT INTO `tbl_state` (`id`, `state_name`) VALUES
(1, 'Delhi'),
(2, 'Uttar pradesh'),
(3, 'Bihar'),
(4, 'Punjab');

You can download source code here