日期:2014-05-18  浏览次数:20798 次

[求助]有关select中onchange(和JSP,MYSQL有一定关系)
要实现点击select1中的数据(例如部门A、B、C),使得select2的数据(例如A部门的1、2、3,B部门的4、5、6,C部门的7、8、9)随之改变,JSP应该如何实现?希望大家能给想想办法。请给出一个尽可能完整的例子,多谢!
补充:select1是从数据库读回来的,,而select2的数据也是从数据库读回来的,是动态更新的,我用的是JSP连接MYSQL来实现,就是不清楚,两个都要动态更新的情况下,如何保证选择了select1的一个数据,自动触发select2里面的相应数据,比如我select1选择的部门   是1,那么select2只有1、2、3供用户选择,select1选择的部门   是2,那么select2只有4、5、6供用户选择,select1选择的部门   是3,那么select2只有7、8、9供用户选择.知道的请帮忙解决,十分感谢!

------解决方案--------------------
我没有用过MYSQL,如果在MSSQL里面可以用触发器,不知道MYSQL里面有没有,如有可以用一个INSERT,UPDATE,DELETE触发器
------解决方案--------------------
点击select1时把select2的数据也拿出来
然后用HashMap condition = new HashMap();

condition.put(select1数据, select2的数据);
String[] a={ "1 ", "2 ", "3 "};
如condition.put( "1 ", a);
condition.get(key)

String[] condition.get( "1 ")
------解决方案--------------------
//当局下拉列表的值确定的时候,那么处下拉列表的值也随之变化
function juChange(parentId){
//当局下拉列表的值变化的时候,将处下拉列表的值进行清空,避免出现处和下拉列表的值重复的情况
document.formAct.chu.length=0;
//得到处记录集的所有个数,并将其赋给js变量count
var count = <%=chuList.size()%> ;
//定义一个js数组,将所有处站点的数据集逐一赋给js数组
var selChu = new Array();
<%
for(int i=0;i <chuList.size();i++){
int id = (((Dept)chuList.get(i)).getId()).intValue();
String name = ((Dept)chuList.get(i)).getName();
Integer pid = ((Dept)chuList.get(i)).getParentid();
System.out.println( "id= "+id+ " name= "+name+ " pid= "+pid);
%>
selChu[ <%=i+1%> ]=new Array( " <%=id%> ", " <%=name%> ", " <%=pid%> ");
<%
}
%>
selChu[0]=new Array( " ", " ",parentId);
for(var i=0;i <count+1;i++){
if(selChu[i][2]==parentId){
document.formAct.chu.options[document.formAct.chu.length] =
new Option(selChu[i][1],selChu[i][0]);
}
}
}
然后在局的那个下拉列表中进行如下动作:
<select name= "ju " style= "width:220 "
onchange= "juChange(document.formAct.ju.options[document.formAct.ju.selectedIndex].value) ">