[英]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.