1

我有一个链接 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 代码是 -

 <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>
4

1 回答 1

1

一个快速演示向我展示了所有警报:

JSFiddle

你确定这不是缓存问题吗?您可以尝试在 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>&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>
于 2013-10-21T10:28:56.057 回答