主题:[讨论]级联下拉列表框
vincent07
[专家分:0] 发布于 2007-02-04 10:37:00
这个问题很棘手,希望能帮忙解决
回复列表 (共2个回复)
沙发
Web乐水 [专家分:1050] 发布于 2007-02-04 11:30:00
显示页面我写的里面数据库字段自己改下
希望你能看懂
注意js是必须的还有<iframe id="hiddenFrame" name="hiddenFrame" width="0" height="0" frameborder="0"></iframe>
也是必须的
测试的时候就只改数据库和相应的字段吧不然会弄糊涂的
<%@ page contentType="text/html;charset=gb2312"%>
<%@ include file="user_islogin.jsp"%>
<%@ include file="conn.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<script>
function dispSubList(o,listid){
var id=o.options[o.selectedIndex].value;
var url="user_hyselect.jsp?pid="+id+"&sublistid="+listid;
frames.hiddenFrame.document.location=url;
}
</script>
<body>
<form name="form1" method="post" action="">
<select name="type" id="type" onChange="dispSubList(this,'type1');">
<option>请选择</option>
<%
String sSjid="13145920";
String SQL="select Id,Name from Profession where SupId='"+sSjid+"'";
Statement stmt=conn.createStatement();
ResultSet Rs=stmt.executeQuery(SQL);
while(Rs.next()){
String Type_id=Rs.getString("Id");
String Type_name=Rs.getString("Name");
out.println("<option value="+Type_id+">"+Type_name+"</option>");
}
%>
</select>
<select name="type1" id="type1">
<option>请选择</option>
</select>
</form>
</body>
<iframe id="hiddenFrame" name="hiddenFrame" width="0" height="0" frameborder="0"></iframe>
</html>
接受页面
<%@ page contentType="text/html;charset=gbk"%>
<%@ include file="conn.jsp"%>
<%
String pid=request.getParameter("pid");
String sublistid=request.getParameter("sublistid");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>取得下拉菜单值</title>
<script language="javascript">
function init(){
var oList=parent.document.getElementById("<%=sublistid%>");
oList.length=0;
<%
String id=null;
String name=null;
String sql="select Id,Name from Profession where SupId='"+pid+"'";
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
while (rs.next()){
id=rs.getString("Id");
name=rs.getString("Name");
%>
var opt=document.createElement("option");
opt.value="<%=name%>";
opt.text="<%=name%>";
oList.add(opt);
<%
}
rs.close();
stmt.close();
conn.close();
%>
}
</script>
</head>
<body onLoad="init()">
</body>
</html>
板凳
liyanjie87217 [专家分:100] 发布于 2007-02-10 20:10:00
用 页面传递 + if判断语句 + HTML语句 即可完成
我来回复