我找过这个网站,使多重下拉: 罗山的博客
而且大部分是工作,我只是具有第三下拉框的问题。
(Dropdown1:客户端,Dropdown2:位置,Dropdown3:区)
在我的网页,到目前为止,如果我看源,选择第一个下拉列表(客户端1)之后,第二个下拉声明说:
<select style="width: 150px;" id="add-event-dialog-location" name="add-event-dialog-location" onchange="getZone(Client1,this.value)">
这正是我需要的,但现在,当我在第二次下降点击其中的一个选项了,它不通过getZone()脚本中放置。 在“zonediv”没有改变,我不知道,如果其余正在经历或没有。 如果我本身以及发生在我自己的GET语句到URL加载getZone.php,我得到的结果,但我不能。我打电话从下拉式菜单页面内得到他们。
我可能只是缺少小东西,但我一直在这么长的好看,我只是无法弄清楚。
该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);
}
}
getLocation.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>