关联表单

songqiu 2007-06-25 07:28:41
本人想写一个关联菜单,两个<select></select>中的<option>都是从数据库中提取,现在两个都能从数据库中提取,但在显示第二个<select>中的<option>是出了问题,第二个<select>中的<option> 是用JavaScript生成.请各位看哈,能否提出意见谢谢啦!
jsp页面的内容如下:
<%@ page contentType="text/html;charset=gbk"%>
<%@ page import="com.cn.favorable.VaritualDataBase3"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.cn.favorable.Favorable"%>
<%@ page import="com.cn.service.ChargeType"%>
<%@ page import="com.cn.department.VaritualDataBase2"%>
<%@ page import="java.util.Iterator" %>
<%@ page import="com.cn.service.Lant" %>
<html>
<head>
<script language="JavaScript">
var oneCount;
oneCount=0;
<%
int ncount;
VaritualDataBase3 db3=new VaritualDataBase3();
ArrayList array=db3.showChageType();
for(ncount=0;ncount<array.size();ncount++ ){
ChargeType chargeType=(ChargeType)array.get(ncount);
%>

subcat[<%=ncount%>]=new Array("<%=chargeType.getChargeType()%>","<%=chargeType.getChargeName()%>","<%=chargeType.getChargeHighType()%>");

<%

System.out.println("chargeType.getChargeType()="+chargeType.getChargeType());

}
System.out.println("123456789="+ncount);

%>

oneCount=<%=ncount%>;

document.writeln(oneCount);

function SelectChageTypeHigh(locationid){

document.addFavorablet.ChageType.length=0;

var locationid=locationid;

var i;



for(i=0;i<oneCount;i++){

if(subcat[i][2]==locationid){
<%
System.out.println("987654321");
%>
document.addFavorablet.ChageType.options[document.addFavorablet.ChageType.length] = new Option(subcat[i][1],subcat[i][0]);
<%
System.out.println("987654321");
%>
}


}

}

</script>
</head>
<body>


<form name="addFavorablet" action="index.jsp" method="get">
<input type="hidden" name="path" value="favorable/data3.jsp">
<input type="hidden" name="mode" value="addFavorablet">
<table width="89%" height="648" border="8" align="center" cellpadding="0" cellspacing="2" bordercolor="D7D9E5">
<tr>
<td width="22%">
<div align="right">
费用类型编号:
</div>
</td>
<td width="78%" height="40">
<select name="ChageTypeHigh" OnChange="SelectChageTypeHigh(document.addFavorablet.ChageTypeHigh.options[document.addFavorablet.ChageTypeHigh.selectedIndex].value)" size="1">


<%
String selected="";
int nCount=0;
boolean bool=false;
VaritualDataBase3 var3 = new VaritualDataBase3();
ArrayList arraylist1=var3.showChageTypeHigh();
for(int index=arraylist1.size()-1;index>=0;index--){
selected="";
ChargeType chargetype=new ChargeType();
chargetype=(ChargeType)arraylist1.get(index);

if(nCount==index)
{
bool=true;
selected="selected";
}
%>
<option value="<%=chargetype.getChargeType()%>" <%=selected%> > <%=chargetype.getChargeName()%>
<%

}
%>
</select>
</td>
</tr>




<tr>
<td width="22%">
<div align="right">
费用类型方案:
</div>
</td>
<td width="78%" height="40">
<select name="ChageType">
<!-- 用JavaScript-->
</select>


</td>
</tr>


<tr>
<td>
</td>
<td height="40">
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
</html>

运行结果:(eclipse控制台)

/*是System.out.println("chargeType.getChargeType()="+chargeType.getChargeType()); 运行的结果:subcat*/
chargeType.getChargeType()=1002
chargeType.getChargeType()=1003
chargeType.getChargeType()=1007
chargeType.getChargeType()=1008
chargeType.getChargeType()=1013
chargeType.getChargeType()=1014
chargeType.getChargeType()=1015
chargeType.getChargeType()=1016
123456789=8
987654321/* 为什么for中的if 只执行了一次*/
987654321
联接成功!


说明: oneCount=<%=ncount%>;为8
document.write(locationid); 可以测出来
以是下网页的源代码中的从数据库中提出的存入subcat中的值
subcat[0]=new Array("1002","甲种正机月租","1001");
subcat[1]=new Array("1003","乙种正机月租","1001");
subcat[2]=new Array("1007","512K ADSL月租","1006");
subcat[3]=new Array("1008","1M ADSL月租","1006");
subcat[4]=new Array("1013","来电显示费","1012");
subcat[5]=new Array("1014","三方通话费","1012");
subcat[6]=new Array("1015","闹钟服务费","1012");
subcat[7]=new Array("1016","免扰服务费","1012");

问题:为什么for中的if 只执行一次?如何去修改?
还没有简单的方法实现这样的效果?



...全文
142 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧