onclick下拉菜单上的两个xmlhttp函数

two xmlhttp functions on onclick from dropdown

本文关键字:两个 xmlhttp 函数 下拉菜单 onclick      更新时间:2024-02-20

经过大量的研究和失败,我正试图从下拉菜单上的一个onclick事件中刷新多个div。我可以用下拉菜单中的onclick事件刷新单个div,但不能处理多个div。有几个stackoverflow页面提到了onclick的类似问题,但没有下拉列表,除非我错过了

这是我迄今为止所拥有的。

<script>
function load_location(str)
{
    if (str=="")
    {
        document.getElementById("location_dd").innerHTML="";
        return;
    }
    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 && xmlhttp.status==200)
        {
            document.getElementById("location_dd").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","ticket_new_user_location.php?property_id="+str,true);
    xmlhttp.send();
}
function load_drive_mapping(str)
{
    if (str=="")
    {
        document.getElementById("drive_mapping_cb").innerHTML="";
        return;
    }
    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 && xmlhttp.status==200)
        {
            document.getElementById("drive_mapping_cb").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","ticket_new_user_drive_mapping.php?property_id="+str,true);
    xmlhttp.send();
}

下拉

<select class="required" name="select_autos" onchange="load_location(this.value)">
 <option value="">Select Auto</option>
 <option value="1">Volvo</option>
 <option value="2">Ford</option>
 <option value="3">BMW</option>
 <option value="4">SAAB</option>
</select>

DIV的

<div id="drive_mapping_cb">

通过将onclick从load_location(this.value)切换到load_drive_mapping(this.value),我可以使每个onclick单独工作,但不能同时处理单个onclick事件。

非常感谢您的帮助。

只需运行两个函数

onchange="load_location(this.value); load_drive_mapping(this.value);"