| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 576 人关注过本帖
标题:javascript 与 jsp的变量
取消只看楼主 加入收藏
HB515560244
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2007-10-9
收藏
 问题点数:0 回复次数:0 
javascript 与 jsp的变量

<%@ 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编辑过]

搜索更多相关主题的帖子: javascript starting PUBLIC import title 
2007-10-24 14:50
快速回复:javascript 与 jsp的变量
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033122 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved