如何设置文本框文本时从下拉列表中选择值


How to set TextBox Text when value selected from DropDown

我有一个名为tblCityState的数据库表,其中包含以下数据:

城市 纽约,洛杉矶,亚特兰大

州 纽约州,

加利福尼亚州,佐治亚

我有一个下拉菜单(ddCity)绑定到表格(从tblCityState中选择城市)。

当用户从下拉列表中选择"洛杉矶"时,我希望文本框 (tbState) 填充"加利福尼亚"。

现在,我可以将下拉项的值设置为"州",但我希望"项"值为"城市"。

实现这一目标的最佳/最简单的方法是什么../这对我来说非常重要。请帮我一些代码。我到处搜索,但没有得到类似的东西。我是php&ajax的新手,建议我一些代码。

索引.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";
    }
}

?>