<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp6.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<jsp:useBean id="myconn" class="DataBase.connectData"></jsp:useBean>
<%
Connection conn=myconn.getconn();
ResultSet rs=null;
ResultSet rs1=null;
Statement stmt=null;
String sql=null;
String sql1=null;
stmt=conn.createStatement();
sql="select * from selec1";
rs = stmt.executeQuery(sql);
%>
<body>
<form action="" method=post name=form1>
<input type="hidden" name="listname" >
<select id="list1" size="1" onchange="fnchange()">
<option value="" selected>--请选择一个--</option>
</select>
<input type="submit" name="submit1" value="提交">
</form>
<select id="list2" size="1">
<option value="" selected>--请选择一个--</option>
</select>
<script type="text/javascript">
<%
while(rs.next()){
%>
var oOption =document.createElement("option");
oOption.text="<%= rs.getString(1)%>";
oOption.value="<%= rs.getString(2)%>";
document.form1.list1.add(oOption);
<%
}
%>
document.all.form1.listname.value=list1.options[list1.selectedIndex].text;
function fnchange(){
document.form1.submit();
<%
request.setCharacterEncoding("gb2312");
String mylistname=request.getParameter("listname");
sql1="select * from selec where name='"+mylistname+"' ";
rs1=stmt.executeQuery(sql1);
int i=rs1.getRow();
out.print(i);
%>
<%
while(rs1.next()){
%>
var oOption =document.createElement("option");
oOption.text="<%= rs.getString(1)%>";
list2.add(oOption);
<%
}
%>
}
</script>
</body>
</html>
如上代码,我就是想得到Javascript中变量list1.options[list1.selectedIndex].text;的值在JSP中用,上面的代码没用,也有很多的不足之处,我只想简单的想实现 当改变list1(select)中的值,list2中的值也能相应的改变,
哪位大哥能帮我看看,最好能修改好帖子再贴上来,
谢谢!
[此贴子已经被作者于2007-10-24 14:53:43编辑过]