选中下拉列表框中一项后改变另一列表框的可选项,这个怎么做啊?
在列表框A中选中一项后,以该项值查询数据库,把结果放进列表框B中。
例如:
数据库C中有username和phone两字段
.....
<select name= "a ">
<option> 未选择 </option>
<%
.....
Connection con = DriverManager.getConnetion(url,user,password);
Statement smt = con.createStatement();
ResultSet rst = smt.executeQuery( "select username from c group by username ");
while(rst.next()) {
out.println( " <option> + rst.getString( "username ") + " </option> ");
}
.....
%>
</select>
<select name= "b ">
</select>
在列表框B中想显示select phone from c where username= 'A中选中的值 '
------解决方案-------------------- <script>
function onchange(select)
{
if(select.value!= " ")
{
location.href= "a.jsp?select= "+select.value;
}
}
</script>
<select name= "a " onchange= "onchange(); ">
<%
.....
Connection con = DriverManager.getConnetion(url,user,password);
Statement smt = con.createStatement();
ResultSet rst = smt.executeQuery( "select username from c group by username ");
while(rst.next()) {
out.println( " <option> + rst.getString( "username ") + " </option> ");
}
</select>
<select name= "b ">
<%
String select =request.getParamter( "select ");
if(select != null && !select.equals( " ")
{
rst = smt.executeQuery( "select phone from c where username= ' "+select+ " ' ");
while(rst.next()) {
out.println( " <option> + rst.getString( "username ") + " </option> ");
}
}else{
out.println( " <option> 未选择 </option> ");
}
%>
</select>