简体   繁体   English

如何使用ajax从两个不同的下拉列表中获取每个选定项目的ID

[英]how to get id of each selected item from two different drop down list using ajax

how to get id of selected item from two different drop down list. 如何从两个不同的下拉列表中获取所选项目的ID。 after comparing them if they were same then how to fetch a record from database without reloading a page using ajax and php. 比较它们是否相同后,如何在不使用ajax和php重新加载页面的情况下从数据库中获取记录。

<select name="bgnm" id="bg" class="demoInputBox" onChange="getState(this.value);">  <?php
     $dd_res=mysql_query("Select * from building");
     while($r=mysql_fetch_row($dd_res))
     { 
           echo "<option value='$r[0]'> $r[1] </option>";
     }

 ?> </select> 




 <select name="flat number" id="flat" onChange="getflat(this.value);"> <?php
     $dd_ress=mysql_query("Select * from building");
     while($r=mysql_fetch_row($dd_ress))
     { 
           echo "<option value='$r[2]'> $r[2] </option>";
     }
 ?>

You can call getValue() function (as described below) whenever a value changes in any of the dropdown. 每当值在任何下拉列表中更改时,您都可以调用getValue()函数(如下所述)。

function getValue() {
var val1=$('bg').val();
var val2=$('flat').val();
if(val1==val2)
{            
     $.ajax({
            url: '{{ url("activeDomain") }}',
            type: 'get',
            //async:true,
            data: {
                id: val1
            },
            dataType: 'json',
            success: function(json) {

              //do whatever you wanted to do
            //you can easily manipulate DOM using jQuery
  },
            error : function(xhr, textStatus, errorThrown ) {
                //in case ajax call error
            }
        });
    }
  }
else{
  //you can send another ajax call
  //use code as above
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置变量或存储下拉列表中的选定项目 - how to set a variable or store selected item from drop down list 如何在下拉列表中显示所选项目? - How to display selected item at drop down list? 如何使用动态ID在HTML下拉列表中选择文本 - How to get selected Text in a HTML drop down using dynamic ID 如何将下拉列表中的其他选定值插入数据库 - How to insert different selected value from drop down list into database 如何使用Java脚本和HTML从下拉的所选两个数字中获得乘法 - How can I get Multiplication from selected two numbers from drop down using java script and html 如何从下拉列表中获取所选值 - How can I get the selected value from a drop down list 如何使用ajax基于两个下拉列表的值从数据库检索数据? - how to retrieve data from database based on the value of two drop down list using ajax? 如何使用下拉列表中的选定值显示数据库中的列表 - How to display the list from database using selected value in drop down 如何使用 php ajax javascript 根据选定的下拉项更改表格的颜色 - how can I change the color of a table based on selected drop down item using php ajax javascript 选择提交时,如何让下拉列表中的每个选项调用不同的功能? - how to have each option in a drop down list call a different function when submit is selected?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM