将2值从2下拉菜单传递到第三下拉菜单

时间:2019-05-20 22:35:51

标签: php ajax

我尝试过在第3个下拉列表中传递值,但它确实收到了其中的任何一个 它没有显示错误,但是没有从2个下拉列表中获取任何数据。我是新手,只是尝试尝试一些东西,但是它根本不起作用,请帮忙。非常感谢 dropdown.php

<svg xmlns="http://www.w3.org/2000/svg" 
     xmlns:xlink="http://www.w3.org/1999/xlink"  
     width="100%" 
     height="100%" 
     viewBox="0 0 100% 100%">
     <g>
     <rect x="50%" y="100%" width="5%" height="15%" >
        <animate id="ra1" attributeName="y" begin="0;ra4.end" dur="1" from="100%" to="40%" fill="freeze" />
        <animate id="ra2" attributeName="height" begin="ra1.end" dur="0.5" by="50" fill="freeze" />
        <animate id="ra3" attributeName="height" begin="ra2.end" dur="0.5" by="-50" fill="freeze" />
        <animate id="ra4" attributeName="y" begin="ra3.end" dur="1" from="40%" to="100%" fill="freeze" />
    </rect>
      </g>
</svg>

deptajax.php 如果我在这里使用request,我会显示错误,但是如果我使用GET,我不会显示任何错误,那么在这种情况下更有用吗?

<select class="form-control" style="font-size: 21px;" name="Building" id="Building" onChange="change_floor(this.value)">
          <option>Select</option>
               <?php
              $res=mysqli_query($conn,"select * from Building");
            while($row=mysqli_fetch_array($res)){
                ?>
    <option  value="<?php echo $row['Building']; ?>"><?php echo $row['Building'];?></option>
              <?php
                 }
                ?>
               </select>

     <select class="form-control" style="font-size: 21px;" name="floor" id="Floor" onChange="change_floor(this.value)">
         <option>Select</option>
       <?php
      $res=mysqli_query($conn,"select * from floor");
      while($row=mysqli_fetch_array($res)){
         ?>
      <option  value="<?php echo $row['Floor']; ?>"><?php echo $row['Floor'];?></option>
         <?php
           }
         ?>
      </select>
            <div id="Dept"></div>
              </div>

</div>
      <script type="text/javascript ">
              function change_floor(str,str1) {

if (str.length == 0) { 
    document.getElementById("Dept").innerHTML = "";
    return;
} else {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("Dept").innerHTML = this.responseText;
        }
    };
    xmlhttp.open("GET", "deptajax.php?q="+str+"&d="+str1, true);
    xmlhttp.send();
}
 }


  </script>

1 个答案:

答案 0 :(得分:0)

您每次onclick的任何下拉菜单时都会调用您的select函数,因此一次仅传递一个值,即:strstr1将具有价值。为了避免这种情况,您可以像下面这样:

首先选择selectbox时尝试尝试store的值,如下所示:

    <select class="form-control" style="font-size: 21px;" name="floor" id="Floor" 
onChange="change_floor1(this.value)">
                 <!--^ make another function  with name change_floor1-->
             <option>Select</option>
          ...
          </select>

然后在您的<script></script>中执行以下操作:

 var s; // declare globally 
 function change_floor1(str) {
   s=str; //assigning value of first-select box in "s"
  }
  function change_floor(str1) {

if (str1.length == 0) { 
    document.getElementById("Dept").innerHTML = "";
    return;
} else {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("Dept").innerHTML = this.responseText;
        }
    };
   //passing both value 
    xmlhttp.open("GET", "deptajax.php?q="+s+"&d="+str1, true);
    xmlhttp.send();
}
 }