我正在查看此站点以进行多重下拉:Roshan 的博客
而且大部分都在工作,我只是遇到了第三个下拉框的问题。
(下拉 1:客户,下拉 2:位置,下拉 3:区域)
到目前为止,在我的页面上,如果我查看源代码,在选择第一个下拉列表(Client1)后,第二个下拉语句说:
<select style="width: 150px;" id="add-event-dialog-location" name="add-event-dialog-location" onchange="getZone(Client1,this.value)">
这是我需要的,但是现在,当我单击第二个下拉菜单中的一个选项时,它不会通过 getZone() 脚本放置。“zonediv”没有改变,我不确定其余的是否通过。如果我自己加载 getZone.php 并将我自己的 GET 语句放入 URL 中,我会得到结果,但我无法在我从中调用下拉列表的页面中获取它们。
我可能只是错过了一些小东西,但我已经看了很长时间,以至于我无法弄清楚。
的HTML:
<select style="width: 150px;" name="add-event-dialog-client_name" id="add-event-dialog-client_name" onchange="getLocation(this.value)">
<?php
echo "<option selected='selected' disabled='disabled'>-Client Name-</option>";
$result = mysql_query("SELECT DISTINCT client_name FROM spc_clients");
while($row = mysql_fetch_array($result)){
echo "<option value='".$row['client_name']."'>".$row['client_name']."</option>";
}
?>
</select>
<p id="locationdiv">
<select style="width: 150px;" name="add-event-dialog-location" id="add-event-dialog-location" disabled="disabled">
<option>Select Client First</option>
</select>
</p>
<p id="zonediv">
<select style="width: 150px;" name="add-event-dialog-zone" id="add-event-dialog-zone" disabled="disabled">
<option>Select Location First</option>
</select>
</p>
两个 JS 函数:
function getLocation(client_name) {
var strURL="display/getLocation.php?client_name="+client_name;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('locationdiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
function getZone(client_name,location) {
var strURL="display/getZone.php?client_name="+client_name+"&location="+location;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('zonediv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
获取位置.php:
<?php
include 'connect.php';
$client = $_GET['client_name'];
$query="SELECT location FROM spc_clients WHERE client_name='$client'";
$result=mysql_query($query) or die(mysql_error());
?>
<select style="width: 150px;" id="add-event-dialog-location" name="add-event-dialog- location" onchange="getZone(<?=$client?>,this.value)">
<option selected='selected' disabled='disabled'>-Location-</option>
<?php
while($row = mysql_fetch_array($result)){
echo "<option value='".$row['location']."'>".$row['location']."</option>";}
?>
</select>
getZone.php:
<?php
include 'connect.php';
$client = $_GET['client_name']; echo $client;
$location = $_GET['location']; echo $location;
$query="SELECT zone FROM spc_clients WHERE (client_name='$client' && location='$location')";
$result=mysql_query($query) or die(mysql_error());
?>
<select style="width: 150px;" id="add-event-dialog-zone" name="add-event-dialog-zone">
<option selected='selected' disabled='disabled'>-Zone-</option><option><?php
while($row = mysql_fetch_array($result)){
echo $row['zone'];}
?>
</option>
</select>