HTML code
< tr > < td width ="146" >< div align ="right" class ="STYLE2" > 选择院系: </ div ></ td > < td width ="150" > < select name ="yuanXi" id ="yuanXi" class ="lbsx" onchange ="changedYX();return false;" > < option value ="-1" > 请选择院系 </ option > < c:forEach items ="${deps.deps}" var ="dep" > < option value ="${dep.bianHao}" > ${dep.mingCheng} </ option > </ c:forEach > </ select > </ td > < td > < div id ="cheResForYX" >< img src ="/fiveF/html/images/question.gif" /></ div > </ td > </ tr > < tr > < td > < div align ="right" class ="STYLE2" > 选择专业: </ div ></ td > < td > < select name ="zhuanYe" size ="1" class ="lbsx" id ="zhuanYe" onchange ="changedZY();return false;" > < option value ="-1" > 请选择专业 </ option > </ select > </ td > < td > < div id ="cheResForZY" >< img src ="/fiveF/html/images/question.gif" /></ div > </ td > </ tr >
-
JScript code
-
function changedYX() { var opt = document.getElementById( " yuanXi " ); if ( true == createXmlHttp()) { xmlHttp.onreadystatechange = processForYX; xmlHttp.open( " POST " , " /fiveF/addCourseForTea " , true ); xmlHttp.setRequestHeader( " Content-Type " , " application/x-www-form-urlencoded; " ); xmlHttp.send( " cmd=yuanxi&yuanXiBH= " + opt.options(opt.selectedIndex).value); } } function processForYX() { if ( 4 == xmlHttp.readystate) { if ( 200 == xmlHttp.status) { // fillNJ(); fillMC(); } } } function fillMC() { clearOption( " zhuanYe " ); var optZY = document.getElementById( " zhuanYe " ); var resultZY = xmlHttp.responseXML.getElementsByTagName( " optionsMC " )[ 0 ]; var options = resultZY.getElementsByTagName( " option " ); var newOption = null ; for ( var i = 0 ;i < options.length;i ++ ) { var option = options[i]; newOption = document.createElement( " option " ); newOption.appendChild(document.createTextNode(option.firstChild.nodeValue)); optZY.appendChild(newOption); } newOption = document.createElement( " option " ); newOption.appendChild(document.createTextNode( " 请选择专业 " )); optZY.appendChild(newOption); newOption.selected = true ; }
Java code if ( " yuanxi " .equalsIgnoreCase(cmd)) { String yuanXiBH = req.getParameter( " yuanXiBH " ); // MyBeans.Grades gras=new MyBeans.Grades(); MyBeans.Majors majs = new MyBeans.Majors(); // gras.fillIn(yuanXiBH); majs.fillIn(yuanXiBH); StringBuffer sb = new StringBuffer(); sb.append( " <root> " ); /* sb.append("<optionsNJ>"); for(int i=0;i<gras.getGras().length;i++) { sb.append("<option>"); sb.append(gras.getGras()[i].getGrade()); sb.append("</option>"); } sb.append("</optionsNJ>"); */ sb.append( " <optionsMC> " ); for ( int i = 0 ;i < majs.getMajs().length;i ++ ) { sb.append( " <option> " ); sb.append(majs.getMajs()[i].getMaj()); sb.append( " </option> " ); } sb.append( " </optionsMC> " ); sb.append( " </root> " ); PrintWriter out = resp.getWriter(); out.print(sb.toString()); }