1

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>&nbsp;</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>&nbsp;</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>
3
  • You should post the HTML received by the client, not the server code that generates it. Commented Oct 21, 2013 at 10:01
  • If you are on Chrome/Firefox, it would be helpful to check Error console in your browser. Commented Oct 21, 2013 at 10:04
  • @Nishan Thanks for the help. Now I am trying to find the problem through Error console. Uncaught TypeError: Cannot set property 'action' of undefined Commented Oct 21, 2013 at 14:55

1 Answer 1

1

A quick demo shows me all the alerts:

JSFiddle

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>&nbsp;</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>&nbsp;</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>
Sign up to request clarification or add additional context in comments.

1 Comment

No caching problem.This is the error giving in chrome error console - Uncaught TypeError: Cannot set property 'action' of undefined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.