dtnpf35197 2017-04-07 08:47
浏览 39

无法将数据检索到文本框中

in my form have three listbox elements that all are working fine, but I need to update it so that when I select the state then similar states that city are added to the state select list. Can anyone help with this?

my dropdown3.php file is:

<html>
<body>
<?Php
session_start();
require "head.php";
require "config.php";
echo "</head><body>";
echo "<table><tr><form method=post id=f1 action=dropdown3-ck.php>
<td>";
$sql="select * from plus2_country";
echo "<select class='form-control' id=country_code name=country_code><option value=''>Select Country</option>";
foreach ($dbo->query($sql) as $row) {
echo "<option value=$row[country_code] >$row[country]</option>";
}
echo "</select></td> 
<td><select class='form-control' id=state_id name=state_id><option value=''>Select State</option></select>
</td>";
echo "<td><select class='form-control' id=city_id name=city_id><option value=''>Select City</option></select>";
//<input name="city_id"  type="text" id="city_id" value='' >"; //i use this for get in to tex box
echo "</td><td><input type=submit value=Submit id=b1></div></form></td></tr></table>";
?>

<script>
$(document).ready(function() {
////////////////Country list box on Change////////////////////
$("#country_code").change(function(){ // change function of listbox
$("#state_id,#city_id").empty();// Remove the existing options 

$.post( "dropdown3ck.php", {"country_code":$('#country_code').val()},function(return_data,status){
$("#state_id").append("<option value=''>Select State</option>");

$.each(return_data.state, function(key,value){
$("#state_id").append("<option value=" + value.state_id +">"+value.state_id + ':' + value.state+"</option>");
});

},"json");

});
///////////////////////////
////////////// State list box on change //////////////////////
$("#state_id").change(function(){ // change function of listbox
$.post( "dropdown3ck.php", {"state_id":$('#state_id').val()},function(return_data,status){

$.each(return_data.city, function(key,value){
$("#city_id").append("<option value=" + value.city_id +">"+value.city+"</option>");
});
},"json");

});
})
</script>
</body>
</html>

my dropdown3ck.php file is:

<?Php
require "config.php"; // connection details
error_reporting(0);// With this no error reporting will be there

$country_code=$_POST['country_code'];// 
$state_id=$_POST['state_id']; /// State Id 

if(strlen($country_code) > 0){
$q_country="select state,state_id from plus2_state where country_code = :country_code";
}
$sth = $dbo->prepare($q_country);
$sth->bindParam(':country_code',$country_code,PDO::PARAM_STR, 15);

$sth->execute();
$state = $sth->fetchAll(PDO::FETCH_ASSOC);
$q_state="select city_id,city from plus2_city where ";

if(strlen($state_id) > 0){
$q_state= $q_state . " state_id = :state_id ";
}
$sth = $dbo->prepare($q_state);
$sth->bindParam(':state_id',$state_id,PDO::PARAM_STR, 25);
$sth->execute();

$city = $sth->fetchAll(PDO::FETCH_ASSOC);
$main = array('state'=>$state,'city'=>$city,'value'=>array("state1"=>"$state1","city1"=>"$city1"));
echo json_encode($main); 
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大