根据以前的下拉值填充第三个菜单

我有三个下拉菜单,前两个工作正常,第三个给我同样的头痛。 由于某种原因,一旦第二个下拉值改变,它就会丢失第一个菜单的值。 这是代码:

 function getXMLHTTP() { //function to return the xml http object var xmlhttp=false; try{xmlhttp=new XMLHttpRequest(); } catch(e){try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; }}} return xmlhttp; } function getColor(CategoryId) { var strURL="getColor.php?Category="+CategoryId; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('qcolor').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } 

直到这里所有似乎都工作其余的是错误但不确定是什么:

 function getBrand(CategoryId,ColorId) { var strURL="getBrand.php?Category="+CategoryId+"&Color="+ColorId; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('qbrand').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } 

HTML代码:

    
Product
Any <option value="Keyboard">Keyboard <option value="Piano">Piano
Colour
Select Color
Brand
Any

getColor.php

   <?php echo 'Any'; while ($Color = mysql_fetch_array($result)) { $selected2 = $_GET['Color'] == $Color['Color'] ? 'selected' : ''; echo '' . $Color['Color'] . ''; } ?>  

这是getBrand.php

   Select Brand  <option value=>   

这个输出颜色是正确的,但是一旦改变为选中它就不会回显出类别值,或者至少当我试图进入getBrand文件时,找不到它是否有办法将类别的值发送为以及getBrand文件?

欢迎任何帮助

在你的getColor.php文件中:

答:您没有在选项标签中传递value属性。

B:在getBrand函数中你得到两个变量; 一个是CategoryId ,另一个是ColorId ,但在品牌选择框的Onchangefunction中,您只传递一个值THIS.VALUE

编辑代码: