这是在我的资金表中显示所有详细信息的 jsp,然后提供一个用于删除任何一个的复选框。但现在我想添加一个 javascript 来检查是否选中了至少一个复选框,以便不会浪费一个 db 调用。 .
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Deleting Funds</title>
<script type="text/javascript">
var checkForm = function(form){
var inputs = form.getElementsByTagName('input');
for(var i = 0, l = inputs.length; i < l; i++){
var input = inputs[i];
if(input.type == "checkbox" && input.checked)
return true;
}
alert('none are checked');
return false;
};
</script>
</head>
<body>
<%
Enumeration names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
StringBuffer sb = new StringBuffer(name);
com.mini.funds.Admin.Delete(sb.toString());
}
%>
<br>
<div class="navigator">
<a href="index.html">Add</a>
<a id="currenttab" href="delete.jsp">Delete</a>
<a href="update.jsp">Update</a>
</div>
<br> <br> <br>
<form action="deleteFunds.jsp" method="post" onsumbit="return checkForm(this);">
<table>
<tr>
<th>code</th>
<th>name</th>
<th>type</th>
<th>nav</th>
<th>min_holdings</th>
<th>desription</th>
<th>terms</th>
<th>check</th>
</tr>
<%
ArrayList<MutualFund> al = com.mini.funds.Admin.GetFunds();
String id;
String box = null;
int num = al.size();
int i=0;
while(i<num)
{
MutualFund almf = al.get(i);
out.print("<tr>");
out.print("<td>");
String code = almf.getMf_code();
out.print(code);
out.print("</td>");
out.print("<td>");
String x = almf.getMf_name();
out.print(x);
out.print("</td>");
out.print("<td>");
String y = almf.getMf_type();
out.print(y);
out.print("</td>");
out.print("<td>");
int a = almf.getNav();
out.print(a);
out.print("</td>")
;
out.print("<td>");
int b = almf.getMf_min_holdings();
out.print(b);
out.print("</td>");
out.print("<td>");
String z = almf.getMf_description();
out.print(z);
out.print("</td>");
out.print("<td>");
String l = almf.getMf_TandC();
out.print(l);
out.print("</td>");
out.print("<td>");
box = "<input name=" + code + " type='checkbox'>";
out.print(box);
out.print("</td>");
out.print("</tr>");
i++;
}
%>
</table>
<br>
<input type="submit" value="Delete">
</form>
</body>
</html>