Reputation: 651
I have a link RESET YEAR which is calling a servlet which is checking whether the current year is present year or not .If they are not equal, then a function resetyear() is called.The function is getting called but the problem is that the function is not working properly. I am giving action to the form. But it is not taking that action and not submitting it. It is just giving alert till "hello". My function flow is not going beyond that alert.
Please provide me suggestions.
My functions are -
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");
}
and 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>
Upvotes: 1
Views: 4178
Reputation: 1956
A quick demo shows me all the alerts:
Are you sure this is not a caching issue? You can try to debug your javascript code in Chrome or Firefox and see what is going on.
As I have a JSFiddle link, I have to include some code here. Here's the code from 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>
Upvotes: 1