<SCRIPT LANGUAGE=JavaScript>
function chgBuBoxOptions(cpBoxNm,bksBoxNm){
//alert("start");

if(cps.length<=0){
alert("eror");
return true;
} //clear
document.forms[0].all(bksBoxNm).length = 0;
//document.forms[0].bukasonm_selway.selectedIndex = 0; //get cpcd value
var cpVal = document.forms[0].all(cpBoxNm).value; //alert(cpVal); var index = 0;

//get new options
for(var i =0; i < cps.length; i++){ if( cps[i][0] == cpVal ){
index = i;
break;
}
} document.forms[0].all(bksBoxNm).length = cps[index][2].length; for (var i = 0; i < cps[index][2].length; i++) {
document.forms[0].all(bksBoxNm).options[i].value = cps[index][2][i][0];
document.forms[0].all(bksBoxNm).options[i].text = cps[index][2][i][1];
}}var cps = new Array();
<ec:loop source="cpArray">
cps[<ec:value index='3'/>] = new Array("<ec:value index='0'/>","<ec:value index='1'/>",<ec:value index='2' escape='false'/>);
</ec:loop>
</SCRIPT>至于这里的标签是从java程序里面获取数据,你可以在这里直接改成去数据库中检索

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/1465/1465024.xml?temp=.2572138
      

  2.   

    试试这个,个人认为比较简单:
    首先是将数据库中读入二维数组中(如果不是数据库直接写就可以了:
    <script language = "javascript">
      var myArray= new Array();
      <%
        for ( int i = 0; i < firstNum; i ++ ){ //firstNum为第一个下拉框中元素的个数,在你这里,有可能要从数据库中得到
          out.print( "myArray[" + i + "]= new Array(); " );
        }
        for ( int i = 0; i < firstNum; i ++ ){
          for ( int j = 0; j < secondNum; j ++ ){
            out.print( "myArray[" + i + "][" + j + "]='" + <%=str%>+"';//str为你的第二个下拉框对应第一个下拉框中第i个值时的值,在你这里,有可能要从数据库中得到
          }
        }
      %>
      function change(){
          document.all( "first" ).options.length = 1;
          if ( document.all( "first" ).selectedIndex == 0 ){
            document.all( "first" ).selectedIndex = 0;
            return;
          }
          selIndex=document.all("first").selectedIndex;      for(i=0;i<myArray[selIndex].length;i++)
          {
            document.all("second").options.add(new Option(myArray[selIndex][i],myArray[selIndex][i]));
          }
        }
    </script>jsp程序中包含:<font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
       请选择地区:
    </font>
    <select name = "first" onchange = "change()">
      <option value = "">==========</option>
      <%
        for ( int i = 0; i < allRegion.size(); i ++ ){
          region regionInfo = ( region )allRegion.elementAt( i );
       %>
       <option value = <%= new String( regionInfo.getRegionName().getBytes( "gb2312" ), "ISO8859_1" )%>>
       <%= new String( regionInfo.getRegionName().getBytes( "gb2312" ), "ISO8859_1" )%>
       </option>
    </select>
       
    <font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
       请选择城市:
    </font>
    <select name = "second">
        <option value = "">==========</option>
    </select>