I have a link RESET YEAR which triggers a servlet to check if the current year is equal to the present year. If they are not equal, then the function resetyear() is supposed to be called. The issue I am facing is that the function is not working as expected. Despite assigning an action to the form, it fails to submit and only displays alert till "hello". The flow of my function seems to get stuck at this point.
I would appreciate any suggestions or recommendations you might have.
Here are the functions in question:
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")
document.forms[0].submit();
alert("over");
alert(1);
}
else{
alert("nothing");
}
}
function dontreset()
{
alert("YOU CAN'T RESET THE YEAR");
}
and here is the HTML CODE:
<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>