方法1:
“enterprise”改变的时候,把 form Submit 出去,把“department”的值取回来方法2:(我的做法)
所有的 “enterprise”、所有的“department”统统取出来,放在页面中(可以参考csdn的那个什么 javascript面向对象的编程 ), "enterprise" option 的选择变化后,直接调用 javascript 写的函数把“department”的数据更新……
例子:
---------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body>
<form name="form1" method="post" action="">
 <p>
  <select name="select1" onChange="onOfficeSelectChange();">
  </select>
 </p>
 <p>
<select name="select2">
  </select>
 </p>
</form>
<script language="JavaScript" type="text/JavaScript">function CLabelValue (label, value)
{
this.label = label;
this.value = value;
}function CSectionOffice (label, value, OfficeID)
{
this.label = label;
this.value = value;
this.officeID = OfficeID;
}var theOffices = new Array (3);
theOffices[0] = new CLabelValue ("罗湖xx局", "001");
theOffices[1] = new CLabelValue ("福田xx局", "002");
theOffices[2] = new CLabelValue ("蛇口xx局", "003");var theSectionOffices = new Array (10);
theSectionOffices[0] = new CSectionOffice ("罗湖科室1", "001", "001");
theSectionOffices[1] = new CSectionOffice ("罗湖科室2", "002", "001");
theSectionOffices[2] = new CSectionOffice ("罗湖科室3", "003", "001");theSectionOffices[3] = new CSectionOffice ("福田科室1", "004", "002");
theSectionOffices[4] = new CSectionOffice ("福田科室2", "005", "002");
//theSectionOffices[5] = new CSectionOffice ("福田科室3", "006", "002");
theSectionOffices[5] = {label:"福田科室3", value:"006", officeID:"002"};theSectionOffices[6] = new CSectionOffice ("蛇口科室1", "007", "003");
theSectionOffices[7] = new CSectionOffice ("蛇口科室2", "008", "003");
//theSectionOffices[8] = new CSectionOffice ("蛇口科室3", "009", "003");
theSectionOffices[8] = {label:"蛇口科室3", value:"009", officeID:"003"};
theSectionOffices[9] = new CSectionOffice ("蛇口科室4", "010", "003");
var aNewElement;
for (var i=0; i<theOffices.length; i++)
{
aNewElement = document.createElement("OPTION");
aNewElement.text = theOffices[i].label;
aNewElement.value = theOffices[i].value;document.all.select1.options.add (aNewElement);
}
function onOfficeSelectChange ()
{
var OfficeID = document.all.select1.value;
var aNewElement;
var i;//alert ("you choose: " + OfficeID); // clear old options...
for (i=document.all.select2.length-1; i>=0; i--)
document.all.select2.remove (i);
/*
for (i=0; i<document.all.select2.length; ) //i++)
{
//alert ("length = " + document.all.select2.length + ", i=" + i);
document.all.select2.remove (0);
}
*/ // create new options...
for (i=0; i<theSectionOffices.length; i++)
{
if (theSectionOffices[i].officeID == OfficeID)
{
aNewElement = document.createElement("OPTION");
aNewElement.text = theSectionOffices[i].label;
aNewElement.value = theSectionOffices[i].value;
document.all.select2.options.add (aNewElement);
}
}
}</script></body>
</html>

解决方案 »

  1.   

    我觉得这两种方式实现有问题:
    1:如果在ENTERPRISE改变的时候调用form.submit(),这样就会导致ACTION不知道是要提供DEPARTMENT还是要将数据存入数据库,如果在ACTION中有录入数据的方法,将会使ENTERPRISE一发生改变就会导致数据录入,选择DEPARTMENT就没有意义。
    2:第二种方法的缺点是在JSP中将会有大量的JAVA代码,而且,当用户关闭JAVASCRIPT后,由于页面是完全用JAVASCRIPT方法,将会导致页面不动作
      

  2.   

    你现在是不是把下拉列表的值存在了Form中?
    最好是专门写一个标签来取Enterprise和Department的值
    这样取Department的值是在标签中完成而不是在你的Action中
    优点很明显,多个地方需要这种联动效果的时候不需要第个Action中都写再者保存数据的时候判断一下用户是否点击了保存按钮即可解决你的第一个问题我说的是
    方法1:
    “enterprise”改变的时候,把 form Submit 出去,把“department”的值取回来
    所以不存在第二个问题