JSP 全选问题
做一个邮件系统的时候,我想实现当点击全选的时候,把所有选中的Email都显示在一个文本框中,Email地址是循环读取出来的,,但读取的时候,只读取到第一个Email地址..
哪位大虾帮帮忙......急!
JS页面代码
function SetChecked(boxname,phone){
f=document.form1;
for( i=0 ; i<f.elements.length ; i++){
if (f.elements[i].name==boxname) {
f.elements[i].checked=true;
for(j = 0; j<f.elements[i]..length;j++){
var send = document.getElementById("phone1").value;
document.getElementById("phone1").value = document.getElementById("phone1").value + phone + ";";
}
}
}
}
}
JSP 页面代码
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import = "com.jytg.dao.imp.*, com.jytg.model.*" %>
<%
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 'Message.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">
-->
<style>
.a{
border:none;
cursor:pointer;
}
</style>
</head>
<script>
function SetChecked(boxname,phone){
f=document.form1;
for( i=0 ; i<f.elements.length ; i++){
if (f.elements[i].name==boxname) {
f.elements[i].checked=true;
for(j = 0; j<f.elements[i]..length;j++){
var send = document.getElementById("phone1").value;
document.getElementById("phone1").value = document.getElementById("phone1").value + phone + ";";
}
}
}
}
}
function addPhone(phone){
var send = document.getElementById("phone1").value;
document.getElementById("phone1").value = document.getElementById("phone1").value + phone + ";";
}
</script>
<body>
<form id="form1" name="form1" method="post" action="<%=basePath %>servlet/SendMessage">
<table width="902" height="330" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="32" colspan="5" align="center">短信息发送</td>
</tr>
<tr>
<td width="100" align="center">收件人:</td>
<td colspan="2" align="center">
<textarea name="phone1" id = "phone1" cols="78" rows = "20"></textarea>
</td>
<td width="231" align="center" colspan="2" rowspan="3">
<DIV style="height:330; overflow: scroll;">
<table>
<input type = "button" onclick="SetChecked('p');return false;" value = "全选"/>
<%
UsersDAOImp usersDAO = new UsersDAOImp();
List<Users> list = usersDAO.getUsers();
for(int i = 0; i < list.size(); i++){
Users user = list.get(i);
%>
<tr>
<td>
<input type='checkbox' name='p' value='<%=user.getU_phone() %>' onclick="SetChecked('p','<%=user.getU_phone() %>');" />
<input type = "text" class = "a" onMouseOver="this.style.backgroundColor='plum'" onMouseOut="this.style.backgroundColor='#ffffff'" onClick="addPhone(<%=user.getU_phone() %>)" id = "phone" name = "phone" value = "<%=user.getU_phone() %>" />
</td>
</tr>
<%
}
%>
</table>
</DIV>
</td>
</tr>
<tr>
<td height="172" align="center">正文:</td>
<td colspan="2" align="center">
<textarea name="content" id = "content" cols="78" rows="10"></textarea>
</td>
</tr>
<tr>
<td height="48" colspan="3" align="center"><input type="submit" name="Submit" value="发送" /></td>
</tr>
</table>
</form>
</body>
</html>
[解决办法]
设计思路有问题,不能在选中checkbox的时候就进行拼串,那要是先选中然后取消然,岂不是没有去掉;要是先选中再取消再选中,岂不是拼两次;应该是再最后提交的时候,进行拼串;其实根本用不着拼串,下个页面可以直接接收的,前台只需要判断最少选中一个进行发送就行
[解决办法]
用复选框的value