gpt4 book ai didi

javascript - 根据第 1 个 2 个下拉列表 ID 显示第 3 个下拉列表

转载 作者:行者123 更新时间:2023-12-03 10:24:27 25 4
gpt4 key购买 nike

我想显示一个相互关联的下拉列表。当选择第一个下拉列表(即区域列表)时,相关扇区列表将填充在第二个下拉列表中。直到这我才能做到。但是在选择第二个下拉列表(即选择扇区)后,我想显示基于“面积”和“扇区”的绘图。这部分我无法做到。我只能显示基于“扇区”的绘图,而不是同时显示面积和扇区。

这是我的代码

获取扇区

function showItems(sel) {
var cat_id = sel.options[sel.selectedIndex].value;
$("#output1").html( "" );
$("#output2").html( "" );
if (cat_id.length > 0 ) {

$.ajax({
type: "POST",
url: "fetch_sectors.php",
data: "cat_id="+cat_id,
cache: false,
beforeSend: function () {
$('#output1').html('<img src="loader.gif" alt="" width="24" height="24">');
},
success: function(html) {
$("#output1").html( html );
}
});
}
}

获取地 block (仅基于扇区)

function showItemDet(sel) {
var item_id = sel.options[sel.selectedIndex].value;
$("#output2").html( "" );
if (item_id.length > 0 ) {
$.ajax({
type: "POST",
url: "fetch_plot.php",
data: "item_id="+item_id,
cache: false,
beforeSend: function () {
$('#output2').html('<img src="loader.gif" alt="" width="24" height="24">');
},
success: function(html) {
$("#output2").html( html );
}
});
}
}

我该怎么做?

***编辑****

我做了这样的事情

<script>
function showPlots(area, sector) {
var item_id = sel.options[sel.selectedIndex].value;
var cat_id = sel.options[sel.selectedIndex].value;
$("#output2").html( "" );
if (item_id.length > 0 ) {
$.ajax({
type: "POST",
url: "fetch_plot.php",
data: {area: item_id, sector:cat_id},
cache: false,
beforeSend: function () {
$('#output2').html('<img src="loader.gif" alt="" width="24" height="24">');
},
success: function(html) {
$("#output2").html( html );
}
});
}
}
</script>

和 fetch_plots

   $area = ($_REQUEST["area"] <> "") ? trim( addslashes($_REQUEST["area"])) : "";
echo $area;
$sector = ($_REQUEST["sector"] <> "") ? trim( addslashes($_REQUEST["sector"])) : "";
if ($item_id <> "" && $cat_id<>"") {
$sql = "SELECT * FROM plots where area_id=".$area." AND sec_id=".$sector."";
echo $sql;

$count = mysqli_num_rows( mysqli_query($con, $sql) );
if ($count > 0 ) {
$query = mysqli_query($con, $sql);
?>

<select name="plot">
<option value="">Select Plot</option>
<?php while ($rs = mysqli_fetch_array($query)) { ?>
<option value="<?php echo $rs["plot_id"]; ?>"><?php echo $rs["name"]; ?></option>
<?php } ?>
</select>

<?php
}
}
?>

最佳答案

     $.ajax({
type: "POST",
url: "fetch_plots.php",
data: {area:area, sector:sector},
cache: false,
beforeSend: function () {
$('#output2').html('<img src="loader.gif" alt="" width="24" height="24">');
},
success: function(html) {
$("#output2").html( html );
}
});

fetch_plots.php

$area = (isset($_REQUEST["area"]) ? intval($_REQUEST["area"]) : 0);
// assuming "$area" is an integer, not a varchar
echo $area;
$sector = (isset($_REQUEST["sector"]) ? intval($_REQUEST["sector"]) : 0);
// assuming "$sector" is an integer, not a varchar
echo $sector;
if ( !empty($area) && !empty($sector) ) {
$sql = "SELECT * FROM plots where area_id=" . $area . " AND sec_id=" . $sector;
echo $sql;
$count = mysqli_num_rows( mysqli_query($con, $sql) );
if ($count > 0 ) {
$query = mysqli_query($con, $sql);
?>
<select name="plot">
<option value="">Select Plot</option>
<?php
while ($rs = mysqli_fetch_array($query)) {
?>
<option value="<?php echo $rs["plot_id"]; ?>"><?php echo $rs["name"]; ?></option>
<?php } ?>
</select>
<?php
}
}
?>

关于javascript - 根据第 1 个 2 个下拉列表 ID 显示第 3 个下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29472879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com