我现在做的是这个样子:
<%@ page contentType="text/html; charset=GBK" import="javax.servlet.*,nt.com.database.*,java.sql.Connection,javax.sql.DataSource,java.sql.*,java.io.*,java.util.Vector,java.lang.*,java.lang.String"%>
<html>
<head>
<title>
AddCne添加复合网元
</title>
<script type="" language="Javascript">
function validateForm(){
var NEname = document.form.NEname.value;
var NEdescription = document.form.NEdescription.value;
if(NEname==""||NEdescription=="")
{
alert("提交的信息不完整,请填写完整的信息!");
return false;
}
var i = NEname.length;
if(i>20)
{
alert("复合网元名称太长!长度不超过20个字符,请重新填写!");
return false;
}
var j = NEdescription.length;
if(j>100)
{
alert("复合网元描述太长!长度不超过100个字符,请重新填写!");
return false;
}
document.getdateform.action="javascript:gotoAdd()";
document.getdateform.submit();
return true;
}
function gotoAdd(){
}
function listvalue(tablename){
tableName = tablename;
}
</script>
</head>
<%
//得到一个数据源连接,得到结果
DBFactory dbf = DBFactory.newInstance();
Connection conn = dbf.getConnect();
String sql = "select * FROM "+tableName;//tableName想通过listvalue来得到从而取值!
Vector rs = dbf.query(sql);
%>
<body bgcolor="#f5f5f5">
<form action="" name="form" method="POST">
<table align="center">
<tr align="center">
<td align="center">
<h1 align="center"><font size="5" face="华文新魏">添加复合网元</font></h1>
</td>
</tr>
</table><br/>
<table align="center" width="80%">
<tr align="center">
<td align="left">复合网元名称:<input type="text" name="NEname"></td>
<td align="right">复合网元描述:<input type="text" name="NEdescription"></td>
</tr>
</table><br/>
<table align="center" width="80%">
<tr align="left">
<td align="left">
复合网元组成:
</td>
</tr>
</table><br/>
<table align="center" border="1" cellpadding="1" width="80%">
<tr>
<td>
<form name="form1">
<table>
<tr>
<td align="left">
基本网元类型选择:<select name="sel" id="c_dep" onchange="javascript.listvalue('window.document.form1.sel.options[selectedIndex].value')">
<option value="BNEHost" selected="selected">主机</option>
<option value="BNEProtocol">应用</option>
<option value="BNEPrefix">网段</option>
<option value="BNEInterface">接口</option>
<option value="BNEAs">自治域</option>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<form name="list1">
</form>
<table border="0" width="90%">
<tr>
<td align="center" width="30%">所选基本网元元素列表</td>
<td align="center" width="30%">
<table>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</td>
<td align="center" width="30%">选取的基本网元元素</td>
</tr>
<tr>
<td align="center" width="30%">
<select size="10" name="jbwylb" id="" multiple="multiple">
<option></option>
<%//显示数 %>
</select>
</td>
<td align="center" width="30%">
<table>
<tr>
<td><input type="button" name="add" value="添加" size="20"></td>
</tr>
<tr>
<td><input type="button" name="add" value="删除" size="20"></td>
</tr>
</table>
</td>
<td width="30%" align="center">
<select size="10" name="" id="" multiple="multiple">
<option></option>
</select>
</td>
</td>
</tr>
</table>
</td>
</tr>
</form>
</table><br/>
<table align="center" width="40%">
<tr align="center">
<td align="left" ><input type="button" value="确定" onclick="javascript:validateForm()" size="20"></td>
<td align="right"><input type="reset" value="取消" size="20"></td>
</tr>
</table>
</form>
</body>
</html>
<%@ page contentType="text/html; charset=GBK" import="javax.servlet.*,nt.com.database.*,java.sql.Connection,javax.sql.DataSource,java.sql.*,java.io.*,java.util.Vector,java.lang.*,java.lang.String"%>
<html>
<head>
<title>
AddCne添加复合网元
</title>
<script type="" language="Javascript">
function validateForm(){
var NEname = document.form.NEname.value;
var NEdescription = document.form.NEdescription.value;
if(NEname==""||NEdescription=="")
{
alert("提交的信息不完整,请填写完整的信息!");
return false;
}
var i = NEname.length;
if(i>20)
{
alert("复合网元名称太长!长度不超过20个字符,请重新填写!");
return false;
}
var j = NEdescription.length;
if(j>100)
{
alert("复合网元描述太长!长度不超过100个字符,请重新填写!");
return false;
}
document.getdateform.action="javascript:gotoAdd()";
document.getdateform.submit();
return true;
}
function gotoAdd(){
}
function listvalue(tablename){
tableName = tablename;
}
</script>
</head>
<%
//得到一个数据源连接,得到结果
DBFactory dbf = DBFactory.newInstance();
Connection conn = dbf.getConnect();
String sql = "select * FROM "+tableName;//tableName想通过listvalue来得到从而取值!
Vector rs = dbf.query(sql);
%>
<body bgcolor="#f5f5f5">
<form action="" name="form" method="POST">
<table align="center">
<tr align="center">
<td align="center">
<h1 align="center"><font size="5" face="华文新魏">添加复合网元</font></h1>
</td>
</tr>
</table><br/>
<table align="center" width="80%">
<tr align="center">
<td align="left">复合网元名称:<input type="text" name="NEname"></td>
<td align="right">复合网元描述:<input type="text" name="NEdescription"></td>
</tr>
</table><br/>
<table align="center" width="80%">
<tr align="left">
<td align="left">
复合网元组成:
</td>
</tr>
</table><br/>
<table align="center" border="1" cellpadding="1" width="80%">
<tr>
<td>
<form name="form1">
<table>
<tr>
<td align="left">
基本网元类型选择:<select name="sel" id="c_dep" onchange="javascript.listvalue('window.document.form1.sel.options[selectedIndex].value')">
<option value="BNEHost" selected="selected">主机</option>
<option value="BNEProtocol">应用</option>
<option value="BNEPrefix">网段</option>
<option value="BNEInterface">接口</option>
<option value="BNEAs">自治域</option>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<form name="list1">
</form>
<table border="0" width="90%">
<tr>
<td align="center" width="30%">所选基本网元元素列表</td>
<td align="center" width="30%">
<table>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</td>
<td align="center" width="30%">选取的基本网元元素</td>
</tr>
<tr>
<td align="center" width="30%">
<select size="10" name="jbwylb" id="" multiple="multiple">
<option></option>
<%//显示数 %>
</select>
</td>
<td align="center" width="30%">
<table>
<tr>
<td><input type="button" name="add" value="添加" size="20"></td>
</tr>
<tr>
<td><input type="button" name="add" value="删除" size="20"></td>
</tr>
</table>
</td>
<td width="30%" align="center">
<select size="10" name="" id="" multiple="multiple">
<option></option>
</select>
</td>
</td>
</tr>
</table>
</td>
</tr>
</form>
</table><br/>
<table align="center" width="40%">
<tr align="center">
<td align="left" ><input type="button" value="确定" onclick="javascript:validateForm()" size="20"></td>
<td align="right"><input type="reset" value="取消" size="20"></td>
</tr>
</table>
</form>
</body>
</html>
<select name=itemB>
<%
while(rs.next())
{
%>
<option value='<%=rs.getString(1)%>'><%=rs.getString(2)%></option>
<%
}
%>
</select>
----------------------
javascript模拟代码:<html>
<head>
<title>
AddCne添加复合网元
</title>
<script type="" language="Javascript">
//select移动
function moveSelected(oSourceSel,oTargetSel)
{
//建立存储value和text的缓存数组
var arrSelValue = new Array();
var arrSelText = new Array();
//此数组存贮选中的options,以value来对应
var arrValueTextRelation = new Array();
var index = 0;//用来辅助建立缓存数组
//存储源列表框中所有的数据到缓存中,并建立value和选中option的对应关系
for(var i=0; i<oSourceSel.options.length; i++)
{
if(oSourceSel.options[i].selected)
{
//存储
arrSelValue[index] = oSourceSel.options[i].value;
arrSelText[index] = oSourceSel.options[i].text;
//建立value和选中option的对应关系
arrValueTextRelation[arrSelValue[index]] = oSourceSel.options[i];
index ++;
}
}
//增加缓存的数据到目的列表框中,并删除源列表框中的对应项
for(var i=0; i<arrSelText.length; i++)
{
//增加
var oOption = document.createElement("option");
oOption.text = arrSelText[i];
oOption.value = arrSelValue[i];
oTargetSel.add(oOption);
//删除源列表框中的对应项
oSourceSel.removeChild(arrValueTextRelation[arrSelValue[i]]);
}
}//增加option
function addOptions(val)
{
var oSel = document.all.itemB;
oSel.innerHTML = "";
switch(val)
{
case 'BNEHost':
createOption(oSel,"1","one");
createOption(oSel,"2","two");
createOption(oSel,"3","three");
break;
case 'BNEProtocol':
createOption(oSel,"4","four");
createOption(oSel,"5","five");
createOption(oSel,"6","six");
break;
case 'BNEPrefix':
case 'BNEInterface':
case 'BNEAs':
createOption(oSel,"7","seven");
createOption(oSel,"8","eight");
createOption(oSel,"9","nine");
break;
default:
break;
}
}
function createOption(oSel,val,txt)
{
var oOption = document.createElement("option");
oOption.value = val;
oOption.text = txt;
oSel.add(oOption);
}function validateForm()
{
var NEname = document.form.NEname.value;
var NEdescription = document.form.NEdescription.value;
if(NEname==""||NEdescription=="")
{
alert("提交的信息不完整,请填写完整的信息!");
return false;
}
var i = NEname.length;
if(i>20)
{
alert("复合网元名称太长!长度不超过20个字符,请重新填写!");
return false;
}
var j = NEdescription.length;
if(j>100)
{
alert("复合网元描述太长!长度不超过100个字符,请重新填写!");
return false;
}
document.getdateform.action="javascript:gotoAdd()";
document.getdateform.submit();
return true;
}
</script>
</head>
<body bgcolor="#f5f5f5">
<form action="" name="form" method="POST">
<table align="center">
<tr align="center">
<td align="center">
<h1 align="center"><font size="5" face="华文新魏">添加复合网元</font></h1>
</td>
</tr>
</table><br/>
<table align="center" width="80%">
<tr align="center">
<td align="left">复合网元名称:<input type="text" name="NEname"></td>
<td align="right">复合网元描述:<input type="text" name="NEdescription"></td>
</tr>
</table><br/>
<table align="center" width="80%">
<tr align="left">
<td align="left">
复合网元组成:
</td>
</tr>
</table><br/>
<table align="center" border="1" cellpadding="1" width="80%">
<tr>
<td>
<form name="form1">
<table>
<tr>
<td align="left">
基本网元类型选择:<select name="sel" id="c_dep" onchange="addOptions(this.value)">
<option value="BNEHost" selected="selected">主机</option>
<option value="BNEProtocol">应用</option>
<option value="BNEPrefix">网段</option>
<option value="BNEInterface">接口</option>
<option value="BNEAs">自治域</option>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<form name="list1">
</form>
<table border="0" width="90%">
<tr>
<td align="center" width="30%">所选基本网元元素列表</td>
<td align="center" width="30%">
<table>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</td>
<td align="center" width="30%">选取的基本网元元素</td>
</tr>
<tr>
<td align="center" width="30%">
<select size="10" name="itemB" style="width:70px" multiple="multiple">
</select>
</td>
<td align="center" width="30%">
<table>
<tr>
<td><input type="button" name="add" value=" 添 加 "
onclick="moveSelected(document.all.itemB,document.all.itemC)" size="20"></td>
</tr>
<tr>
<td><input type="button" name="add" value=" 删 除 "
onclick="moveSelected(document.all.itemC,document.all.itemB)" size="20"></td>
</tr>
</table>
</td>
<td width="30%" align="center">
<select size="10" style="width:70px" name="itemC" multiple="multiple">
</select>
</td>
</td>
</tr>
</table>
</td>
</tr>
</form>
</table><br/>
<table align="center" width="40%">
<tr align="center">
<td align="left" ><input type="button" value="确定" onclick="javascript:validateForm()" size="20"></td>
<td align="right"><input type="reset" value="取消" size="20"></td>
</tr>
</table>
</form>
</body>
</html>
基本网元类型选择:<select name="sel" id="c_dep" onchange="addOptions(this.value)">
<option value="BNEHost" selected="selected">主机</option>
<option value="BNEProtocol">应用</option>
<option value="BNEPrefix">网段</option>
<option value="BNEInterface">接口</option>
<option value="BNEAs">自治域</option>
</select>
取一个值到addOptions方法中,这个值怎么能和读取数据库的程序连接上?javascript中不能够读取数据库吧?!!
用hidden来传值,呵呵,不知道可不可行?!!不知道怎么写?!!
<select name=itemB>
<%
while(rs.next())
{
%>
<option value='<%=rs.getString(1)%>'><%=rs.getString(2)%></option>
<%
}
%>
</select>生成select,或者可以使用XmlHttp控件进行局部刷新,就可以在addOptions方法里面增加了,你可以在csdn搜索一下,很多的
呵呵,我太笨了,还是不知道如何实现,你给我个例子!谢谢谢谢!
页面1:
<%@ page contentType="text/html; charset=GBK" import="javax.servlet.*,nt.com.database.*,java.sql.Connection,javax.sql.DataSource,java.sql.*,java.io.*,java.util.Vector,java.lang.*,java.lang.String"%>
<html>
<head>
<title>
AddCne添加复合网元
</title>
<script type="" language="Javascript">
function validateForm(){
var NEname = document.form.NEname.value;
var NEdescription = document.form.NEdescription.value;
if(NEname==""||NEdescription=="")
{
alert("提交的信息不完整,请填写完整的信息!");
return false;
}
var i = NEname.length;
if(i>20)
{
alert("复合网元名称太长!长度不超过20个字符,请重新填写");
return false;
}
var j = NEdescription.length;
if(j>100)
{
alert("复合网元描述太长!长度不超过100个字符,请重新填写!");
return false;
}
document.getdateform.action="javascript:gotoAdd()";
document.getdateform.submit();
return true;
}
function gotoAdd(){ }
function ddd(){
document.ddd.submit();
return true;
}
</script>
</head><body bgcolor="#f5f5f5">
<table align="center">
<tr align="center">
<td align="center">
<h1 align="center"><font size="5" face="华文新魏">添加复合网元</font></h1>
</td>
</tr>
</table><br/>
<table align="center" width="80%">
<tr align="center">
<td align="left">复合网元名称:<input type="text" name="NEname"></td>
<td align="right">复合网元描述:<input type="text" name="NEdescription"></td>
</tr>
</table><br/>
<table align="center" width="80%">
<tr align="left">
<td align="left">
复合网元组成:
</td>
</tr>
</table><br/>
<table align="center" border="1" cellpadding="1" width="80%">
<tr>
<td>
<form name="ddd">
<table>
<tr>
<td align="left">
基本网元类型选择:<select name="itemA" onchange="javascript:ddd();itemA.submit()">
<option selected="selected">-请选择-</option>
<option value="BNEHost">主机</option>
<option value="BNEProtocol">应用</option>
<option value="BNEPrefix">网段</option>
<option value="BNEInterface">接口</option>
<option value="BNEAs">自治域</option>
</select>
</td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td>
<IFRAME ID="test" name=t src="AddCne_b.jsp" width="80%" height=400 FRAMEBORDER=0></IFRAME>
</td>
</tr>
</table><br/>
<table align="center" width="40%">
<tr align="center">
<td align="left" ><input type="button" value="确定" onclick="javascript:validateForm()" size="20"></td>
<td align="right"><input type="reset" value="取消" size="20"></td>
</tr>
</table>
</body>
</html>
页面2:AddCne_b.jsp<%@ page contentType="text/html; charset=GBK" import="javax.servlet.*,nt.com.database.*,java.sql.Connection,javax.sql.DataSource,java.sql.*,java.io.*,java.util.Vector,java.lang.*,java.lang.String"%>
<html>
<head>
<title>
AddCne_b
</title>
</head>
<body bgcolor="#f5f5f5">
<%
//得到一个数据源连接,得到结果
String tableName = request.getParameter("itemA");
if(tableName!=null&&tableName.length()>0&&!tableName.equals("null")){
DBFactory dbf = DBFactory.newInstance();
Connection conn = dbf.getConnect();
String sql = "select * FROM "+tableName;
Vector rs = dbf.query(sql);
%>
<table border="0" width="90%">
<tr>
<td align="center" width="30%">所选基本网元元素列表</td>
<td align="center" width="30%">
<table>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</td>
<td align="center" width="30%">选取的基本网元元素</td>
</tr>
<tr>
<td align="center" width="30%">
<select size="10" name="itemB" style="width:100px" id="" multiple="multiple">
<option></option>
<%
int i=0;
i = rs.size();
int j=0;
while(j<i)
{
String[] result = (String[])rs.elementAt(j);
%>
<option value='<%=result[0]%>'><%=result[0]%></option>
<%
j++;
}
}
%>
</select>
</td>
<td align="center" width="30%">
<table>
<tr>
<td><input type="button" name="add" value="添加" size="20"></td>
</tr>
<tr>
<td><input type="button" name="add" value="删除" size="20"></td>
</tr>
</table>
</td>
<td width="30%" align="center">
<select size="10" name="itemC" id="" multiple="multiple" style="width:100px">
<option></option>
</select>
</td>
</tr>
</table>
</body>
</html>
现在出的错误是:
这行:<select name="sel" onchange="javascript:ddd()">
错误信息是:对象不支持次属性或方法!
你的itemA是什么咚咚,怎么能submit()???
基本网元类型选择:<select name="itemA" onchange="javascript:ddd();itemA.submit()">应该是:<select name="itemA" onchange="javascript:ddd()">
<%@ page import="database.ConnectionLink,java.sql.*" %>
<html>
<%
String userId = request.getParameter("userId");
//得到提交页面的select的状态
String index = request.getParameter("index");
int indexNum = 0;
if(index != null)
indexNum = Integer.parseInt(index,10);
ResultSet rs = null;
try
{
if(userId != null && !userId.equals("0"))
{
ConnectionLink db = new ConnectionLink();
Connection con = db.getConnection();
Statement st = con.createStatement();
String sql = "select name from duser where id = '" + userId + "'";
rs = st.executeQuery(sql);
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
<head>
<script language="javascript">
function subForm()
{
//将当前选中的索引保存到后台,以便于初始化下拉框
document.forms[0].action = "test.jsp?index="
+ document.all.userId.selectedIndex;
document.forms[0].submit();
}function initSelect()
{
var index = <%=indexNum%>;
document.all.userId.selectedIndex = index;
}
</script>
<title>
test
</title>
</head>
<body bgcolor="#ffffff" onload="initSelect()">
<form action="test.jsp" method="POST">
<select name="userId" onchange="subForm()">
<option value="0">请选择</option>
<option value="1">用户1</option>
<option value="2">用户2</option>
</select><p>
<select name="userName">
<%
if(rs != null)
{
while(rs.next())
{
%>
<option><%=rs.getString("name")%></option>
<%
}
}
%>
</select><p>
</form>
</body>
</html>
基本网元类型选择:<select name="itemA" onchange="javascript:ddd.submit();">
应该加“;”
或者:
基本网元类型选择:<select name="itemA" onchange="javascript:ddd();">
也要加";"
好难呀!总于找到问题的所在了!谢谢大家了!!!!!!!!!!