2014-07-22 33 views
0

我想(名字“sub_category)项目依赖于另一个下拉列表(problem_type)项目,显示下拉列表显示下拉列表项依赖于另一个下拉列表项目使用JavaScript

问题类型:选择问题类型中的一种:线路问题,服务问题,
设备发行和结算问题

子类别

线问题 - 噪音线,呼叫干扰,李伤害。

服务问题 - 服务提供商的主要服务中断。

设备问题 - 嘈杂,没有拨号音,损坏的设备。

结算问题 - 帐单支付未更新,帐单错误。

这里是我的代码

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
    <title>Insert title here</title> 
    <script type="text/javascript"> 
     window.onload = function addList(){ 
      int i; 
      var sub = document.forms["raiseNewFault2"]["sub_category"]; 
      var main = document.forms["raiseNewFault2"]["problem_type"].value; 
      var str1 = new Array("Noisy Line", "Call Interference", "Line damage"); 
      var str2 = new Array("Major service outage at Provider"); 
      var str3 = new Array("Noisy", "No Dial Tone", "Damaged Equipment"); 
      var str4 = new Array("Billing paid not updated", "Wrong Billing"); 
      if(main.equals("Line issue")){ 
       for(i=0;i<=2;i++){ 
        var option = document.createElement('option'); 
        option.text = option.value = str1[i]; 
       } 
      } 
      else if(main.equals("Service issue")){ 
       for(i=0;i<=0;i++){ 
        var option = document.createElement('option'); 
        option.text = option.value = str2[i]; 
       } 
      } 
      else if(main.equals("Equipment issue")){ 
       for(i=0;i<=2;i++){ 
        var option = document.createElement('option'); 
        option.text = option.value = str3[i]; 
       } 
      } 
      else if(main.equals("Billing issue")){ 
       for(i=0;i<=1;i++){ 
        var option = document.createElement('option'); 
        option.text = option.value = str4[i]; 
       } 
      } 
      select.add(option); 
     } 
    </script> 
    <style type="text/css"> 
     #raiseNewFault2Div 
     { 
      margin-top : 25px; 
      margin-left : 325px; 
      height : 500px; 
      width : 600px; 
      background-color : #FFDA91; 
      border : ridge; 
      border-width : "3px" 
     } 
    </style> 
</head> 
<body onload="addList()"> 
    <div id="raiseNewFault2Div"> 
     <center> 
      <form name="raiseNewFault2" action="Controller" method="post"> 

       <br/><br/> 
       <font size="3" color="#006E25">Problem type &nbsp;&nbsp; : 
       &nbsp;&nbsp; </font> 
       <select name="problem_type"> 
        <option value="Line issue" selected>Line issue</option> 
        <option value="Service issue">Service issue</option> 
        <option value="Equipment issue">Equipment issue</option> 
        <option value="Billing issue">Billing issue</option> 
       </select> 
       <br/><br/><font size="3" color="#006E25">Sub Category &nbsp;&nbsp; : 
       &nbsp;&nbsp; </font> 
       <select name="sub_category"></select> 
       </from></center> </div></body></html> 

回答

0

最简单的方法是检查什么用户在第一列表已选中,然后用相应的JavaScript更换整个第二列表: -
document.getElementById("put the id of the div which contains the list here").innerHTML="put the list you want to replace with the old one here";

相关问题