Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.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
Javascript 更改第一个组合框后,更改第二个组合框的数据_Javascript_Php - Fatal编程技术网

Javascript 更改第一个组合框后,更改第二个组合框的数据

Javascript 更改第一个组合框后,更改第二个组合框的数据,javascript,php,Javascript,Php,我有两个组合框。第一个组合框有州名,我有从数据库检索到的数据,第二个组合框有到该特定州的地区的数据。我需要的是,在第一个组合框中的数据一旦更改。第二个组合框中的数据也应该更改。这是我的代码 <select name="district" id="district" onchange="showcomplain()"> <?php $query="SELECT * FROM `rev_district_master`"; $result=mysql_query($

我有两个组合框。第一个组合框有州名,我有从数据库检索到的数据,第二个组合框有到该特定州的地区的数据。我需要的是,在第一个组合框中的数据一旦更改。第二个组合框中的数据也应该更改。这是我的代码

<select name="district" id="district" onchange="showcomplain()">
<?php
    $query="SELECT * FROM `rev_district_master`";
    $result=mysql_query($query) or die("Selection query of District Master is Error".mysql_error());
    $num = mysql_numrows($result);
    while($row=mysql_fetch_row($result))
    {
?>
    <option value="<?php echo $row[1];?>"><?php echo $row[1];?></option>
<?php
    }
?> 
This is my ajax file:

function stateComboChange(){

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}else{          
var url="./ajax/list1.php";
xmlHttp.onreadystatechange=stateChanged1 ;
xmlHttp.open("POST",url,true);
xmlHttp.send(null)  ;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
}
catch (e)
{
    //Internet Explorer
    try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
}
return xmlHttp;
}

function stateChanged1() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
document.getElementById("stateCombo").innerHTML=xmlHttp.responseText; }


第二个组合框的数据在哪里?。。。我没有看到这个代码


您可以对数据库使用AJAX请求,并在回调时更改de数据。

通过状态更改时的AJAX调用来实现

function changeCombo(){
                var statename=document.getElementByid('state_combo_box').value;
          if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
            }
            else
            {// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange=function()
            {
                if (xmlhttp.readyState==4 )
                {
                    if(xmlhttp.status==200)
                    {
                       var data=JSON.parse(xmlhttp.responseText);
                for(var index= 0;index<data.length;index++)
                {
                    var combo=document.getElementById('district');
                    combo.options[combo.options.length] = new Option(districtname, value);

}
                    }

                }
            }
            xmlhttp.open("GET","some_php_file_which_echos_data.php",true);
            xmlhttp.send(statename);
        }


    }       
函数changeCombo(){
var statename=document.getElementByid('state\u组合框')。值;
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
var data=JSON.parse(xmlhttp.responseText);

对于(var index=0;indexd)您是想自己编写代码还是有人为您编写代码?在选择第一个组合时使用ajax是否有关于这些类型代码的教程。我对php和ajax不熟悉。谢谢。是否有关于这些类型代码的教程。我对php和ajax不熟悉。很抱歉,回复太晚,但是非常基本的教程您可以点击[链接](www.W3schools.com)