index.php
<script src="jquery.min.js" type="text/javascript"></script>
<script type='text/javascript' src='jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
<script type="text/javascript">
$().ready(function() {
$("#customer").autocomplete("state.php", {
width: 160,
autoFill: true,
selectFirst: false
});
$("#customer").blur(function() {
$("#customer1").val('');
$(".ac_results").next().css('height','0px');
var vState = $("#customer").val();
$("#customer1").autocomplete("city.php?state="+vState, {
width: 160,
autoFill: false,
data:{},
length:0,
});
});
});
</script>
<form name="thisForm1" method="post" id="thisForm1" action="" >
<table cellpadding="5" cellspacing="5" width="50%" align="center" class="ac_results">
<tr><td>
Enter state<input name="customer" type="text" id="customer" value="" style="width:300px;" autocomplete="off" >
</td><td>
Enter Keyword<input name="customer1" type="text" id="customer1" value="" style="width:500px;" autocomplete="off" >
</td></tr>
</table>
</form>
状態.php
<?php
$db = mysql_pconnect('localhost','root','');
mysql_select_db('test',$db);
$q = strtolower($_GET["q"]);
$a = mysql_query("SELECT * FROM state");
while($b = mysql_fetch_object($a))
{
echo "$b->name\n";
}
?>
都市.php
<?php
$db = mysql_pconnect('localhost','root','');
mysql_select_db('test',$db);
$q = strtolower($_GET["q"]);
$vState = $_REQUEST['state'];
if (!empty($vState)) {
$a = mysql_query("SELECT * FROM best_hotel WHERE class = '$vState'");
while($b = mysql_fetch_object($a)) {
echo "$b->name\n";
}
}
?>