[英]issue with jsp page - not displaying popup
我的jsp中有類似以下的代碼,該代碼確定了我的管理主頁上選中的復選框。 我正在使用javascript和Java的混合來獲取和發布數據。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import = "java.sql.*" import = "controller.LoginServlet"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Administrator Home Page</title>
<script type="text/javascript">
function getCheckedBoxes(chkboxName)
{
av = document.getElementsByName("mycheckedbox");
for (var e=0;e<j;e++)
{
if (av[e].checked==true)
{
document.write("Checkbox selected is " + av[e]);
alert(e + " selected");
}
}
}
function redirectUser()
{
var req1 = request.getParameter("subAdd");
var req2 = request.getParameter("subReject");
var frm = document.forms[0];
if(req1 != null && req1.equals("Add"))
{
var pageName = "/LoginServlet?method=add";
frm.action = pageName;
frm.submit();
}
if(req2 != null && req2.equals("Reject"))
{
var pageName = "/LoginServlet?method=reject";
frm.action = pageName;
frm.submit();
}
}
</script>
</head>
<body>
<form name="Admin_Home" action="LoginServlet" method="post">
<%
String user_name = new String();
user_name = request.getParameter("user_name");
%>
<font color="green">Welcome Admin, <% out.println(user_name); %>!!</font>
<table>
<%
int i;
int j = 0;
int count = (Integer)request.getAttribute("count");
String[] first_name = new String[1000];
String[] group_name = new String[1000];
first_name = (String[])request.getAttribute("first_name");
group_name = (String[])request.getAttribute("group_name");
for (i=0; i<count; i++)
{
%>
<tr>
<td><font color="black"><% out.println(first_name[i] + " " + group_name[i]); %></font>
<input type = 'checkbox' value = <% j++; %> name = 'mycheckedbox'></input>
</td>
</tr>
<%
}
System.out.println("value of i = " + i);
%>
<tr>
<td>
<input type="submit" name="subGetChked" id="subGetChked" value = "Get Checked Checkboxes" onclick="getCheckedBoxes('mycheckedbox')">
<input type="submit" name="subAdd" id="subAdd" value = "Add" onclick="getCheckedBoxes('mycheckedbox')">
<input type="submit" name="subReject" id="subReject" value = "Reject" onclick="getCheckedBoxes('mycheckedbox')">
</td>
</tr>
</table>
</form>
</body>
</html>
當我運行頁面時,這沒有顯示復選框選中的警報。 你能幫我這個忙嗎?
任何幫助表示贊賞!
我復制您的代碼n我更改了一些地方。以下是我的html部分:
<html>
<head>
<script type="text/javascript">
function getCheckedBoxes(chkboxName) {
var j =0;
if (chkboxName.checked==true) {
//document.write("Checkbox selected is " + av);
alert(" selected");
}
}
function redirectUser() {
....
}
</script>
</head>
<body>
<form name="Admin_Home" action="LoginServlet" method="post">
<font color="green">Welcome Admin, !!</font>
<table>
<tr>
<td>
<input type = 'checkbox' value = "25" name = 'mycheckedbox' id="one"></input>
</td>
</tr>
<tr>
<td>
<input type="button" name="subGetChked" id="subGetChked" value = "Get Checked Checkboxes" onclick="getCheckedBoxes(Admin_Home.mycheckedbox)">
<input type="submit" name="subAdd" id="subAdd" value = "Add" onclick="getCheckedBoxes('mycheckedbox')">
<input type="submit" name="subReject" id="subReject" value = "Reject" onclick=" getCheckedBoxes('mycheckedbox')">
</td>
</tr>
</table>
</form>
</body>
</html>
它在我的計算機上可以正常工作,希望可以為您提供幫助:D。 還有問題嗎?只要告訴我,我就嘗試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.