我有一个链接RESET YEAR,它调用一个servlet来检查当前年份是否存在。如果它们不相等,则调用函数resetyear()。函数被调用但是问题是功能无法正常工作。我正在对表格采取行动。但它没有采取行动,也没有提交。它只是提醒警告直到“你好”。我的功能流程并未超出该警报范围。
请提供建议。
我的职能是 -
function resetyear(){
if(confirm("DO YOU WANT TO RESET THE YEAR?"))
{
alert("hello");
var formname = document.getElementById("indexform");
alert(formname);
document.forms[0].action = "resetmaster";
alert("hi")
//alert(document.forms['indexform'].action);
document.forms[0].submit();
alert("over");
//form.action = "/resetmaster";
//form.submit();
alert(1);
}
else{
alert("nothing");
}
}
function dontreset()
{
alert("YOU CAN'T RESET THE YEAR");
}
和HTML CODE IS -
<html>
<head>
<title>CHANDNA COLDSTORAGE</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="js/calculateamt.js" type="text/javascript" ></script>
<link href="CSS/style.css" rel="stylesheet" type="text/css">
<script>
function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
</script>
</head>
<% String role = "";
role = (String) session.getAttribute("role");
String flag = "";
flag = (String) session.getAttribute("flag");
System.out.println("flag = " + flag);
if (flag == null) {
flag = "";
}
if (flag.equals("yes")) {
%>
<script>
alert(1);
// resetyear();
dontreset();
//document.getElementById("checkyear").value = "1";
//alert(document.getElementById("checkyear").value);
</script>
<%} else if(flag.equals("no"))
{%>
<script>
alert(2);
//document.getElementById("checkyear").value = "2";
//alert(document.getElementById("checkyear").value);
resetyear();
</script>
<%}else{}%>
<body>
<form name="indexform" method="post" id="indexform">
<div id="maindiv">
<div align="center">
<p> </p>
<p id="Title"> CHANDNA COLD STORAGE </p>
<input type="hidden" name="checkyear" id="checkyear" value="">
</div>
<table width="459" border="0" align="center">
<%if (role != null && role.equals("admin")) {%>
<tr>
<td height="70"><p align="center"><a href="showoctdet.jsp">OCCUPANT'S LIST</a></p></td>
</tr>
<tr>
<td height="70"><p align="center"><a href="/ColdStorage/regisbean">REGISTRATION PAGE</a></p></td>
</tr>
<tr>
<td height="70"><p align="center"><a href="Acceptanceform.jsp">ACCEPTANCE PAGE</a></p></td>
</tr>
<tr>
<td height="70"><p align="center"><a href="CashReciept.jsp">CASH RECIEPT</a></p></td>
</tr>
<tr>
<td height="70"><p align="center"><a href="Report.jsp">REPORT</a></p></td>
</tr>
<tr>
<td height="70"><p align="center"><a href="DetailsTrack.jsp">TRACK DETAILS</a></p></td>
</tr>
<tr>
<td height="70"><p align="center"><a href="/ColdStorage/resetyear">RESET YEAR</a></p></td>
</tr>
<%} else {%>
<tr>
<td height="70"><p align="center"><a href="Report.jsp">REPORT</a></p></td>
</tr>
<%}%>
</table>
<p> </p>
<p align="center">
<input type="submit" name="signout" id="signout" value="SIGN OUT" onClick="MM_goToURL('parent','Login.jsp');return document.MM_returnValue">
</p>
</form>
</body>
</html>
答案 0 :(得分:1)
快速演示向我展示了所有警报:
您确定这不是缓存问题吗?您可以尝试在Chrome或Firefox中调试您的JavaScript代码,看看发生了什么。
由于我有一个JSFiddle链接,我必须在这里包含一些代码。这是来自JSFiddle的代码:
<body>
<script>
function resetyear() {
if (confirm("DO YOU WANT TO RESET THE YEAR?")) {
alert("hello");
var formname = document.getElementById("indexform");
alert(formname);
document.forms[0].action = "resetmaster";
alert("hi")
//alert(document.forms['indexform'].action);
document.forms[0].submit();
alert("over");
//form.action = "/resetmaster";
//form.submit();
alert(1);
} else {
alert("nothing");
}
}
</script>
<form name="indexform" method="post" id="indexform">
<div id="maindiv">
<div align="center">
<p> </p>
<p id="Title">CHANDNA COLD STORAGE</p>
<input type="hidden" name="checkyear" id="checkyear" value="">
</div>
<table width="459" border="0" align="center">
<%if (role !=n ull && role.equals( "admin")) {%>
<tr>
<td height="70">
<p align="center"><a href="showoctdet.jsp">OCCUPANT'S LIST</a>
</p>
</td>
</tr>
<tr>
<td height="70">
<p align="center"><a href="/ColdStorage/regisbean">REGISTRATION PAGE</a>
</p>
</td>
</tr>
<tr>
<td height="70">
<p align="center"><a href="Acceptanceform.jsp">ACCEPTANCE PAGE</a>
</p>
</td>
</tr>
<tr>
<td height="70">
<p align="center"><a href="CashReciept.jsp">CASH RECIEPT</a>
</p>
</td>
</tr>
<tr>
<td height="70">
<p align="center"><a href="Report.jsp">REPORT</a>
</p>
</td>
</tr>
<tr>
<td height="70">
<p align="center"><a href="DetailsTrack.jsp">TRACK DETAILS</a>
</p>
</td>
</tr>
<tr>
<td height="70">
<p align="center"><a href="javascript:resetyear()">RESET YEAR</a>
</p>
</td>
</tr>
<%} else {%>
<tr>
<td height="70">
<p align="center"><a href="Report.jsp">REPORT</a>
</p>
</td>
</tr>
<%}%>
</table>
<p> </p>
<p align="center">
<input type="submit" name="signout" id="signout" value="SIGN OUT" onClick="MM_goToURL('parent','Login.jsp');return document.MM_returnValue">
</p>
</form>
</body>