Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从下拉列表中选择值时如何设置文本框文本_Php_Jquery - Fatal编程技术网

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

Php 从下拉列表中选择值时如何设置文本框文本,php,jquery,Php,Jquery,我有一个名为tblCityState的数据库表,其中包含以下数据: 纽约市、洛杉矶、亚特兰大 纽约州、加利福尼亚州、乔治亚州 我有一个下拉列表ddCity绑定到表Select City from tblCityState 当用户从下拉列表中选择Los Angeles时,我希望文本框tbState中填充California 现在,我可以将下拉项的值设置为State,但我希望该项的值为City 实现这一点的最佳/最简单的方法是什么../这对我来说非常重要..请帮我编写一些代码。我到处搜索,但没有找到

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

纽约市、洛杉矶、亚特兰大

纽约州、加利福尼亚州、乔治亚州

我有一个下拉列表ddCity绑定到表Select City from tblCityState

当用户从下拉列表中选择Los Angeles时,我希望文本框tbState中填充California

现在,我可以将下拉项的值设置为State,但我希望该项的值为City

实现这一点的最佳/最简单的方法是什么../这对我来说非常重要..请帮我编写一些代码。我到处搜索,但没有找到类似的内容。我是php和ajax新手。请给我推荐一些代码。

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




?>
city.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";
    }

}


?>

展示你迄今为止所做的尝试。那么只有我们能帮助你,这是不可能的。你必须先展示你的一些研究和努力。作为一个提示,我建议您查看AJAX,根据urstextbox更改表名,只有在那里您才检查。。这是一个自动完成。我想从数据库中选择一个州的一个城市。州在下拉列表中。选择它后,textfield将显示它的城市。希望我对所有人都清楚。在这里,您可以编写与您的表相关的查询