title: Form action in javascript function not working
body: <p>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. </p>
  
  <p>Please provide me suggestions.</p>
  
  <p>My functions are -</p>
  
  <pre><code> 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");
  }
  </code></pre>
  
  <p>and HTML CODE IS -</p>
  
  <pre><code> &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;CHANDNA COLDSTORAGE&lt;/title&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;script src="js/calculateamt.js" type="text/javascript" &gt;&lt;/script&gt;
      &lt;link href="CSS/style.css" rel="stylesheet" type="text/css"&gt;
      &lt;script&gt;
          function MM_goToURL() { //v3.0
              var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
              for (i=0; i&lt;(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
          }
      &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;% 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")) {
  %&gt;   
  &lt;script&gt;
  
     alert(1);
    // resetyear();
      dontreset();
      //document.getElementById("checkyear").value = "1";
      //alert(document.getElementById("checkyear").value);
  
  &lt;/script&gt;
  &lt;%} else if(flag.equals("no"))
      {%&gt;
  &lt;script&gt;
      alert(2);
      //document.getElementById("checkyear").value = "2";
      //alert(document.getElementById("checkyear").value);
      resetyear();
  &lt;/script&gt;
  &lt;%}else{}%&gt;
  &lt;body&gt; 
      &lt;form name="indexform" method="post" id="indexform"&gt;
          &lt;div id="maindiv"&gt;
              &lt;div align="center"&gt;
                  &lt;p&gt;&amp;nbsp;&lt;/p&gt;
                  &lt;p id="Title"&gt; CHANDNA COLD STORAGE &lt;/p&gt;
  
                  &lt;input type="hidden" name="checkyear" id="checkyear" value=""&gt;
              &lt;/div&gt;
  
              &lt;table width="459" border="0" align="center"&gt;
  
                  &lt;%if (role != null &amp;&amp; role.equals("admin")) {%&gt;
                  &lt;tr&gt;
                      &lt;td height="70"&gt;&lt;p align="center"&gt;&lt;a href="showoctdet.jsp"&gt;OCCUPANT'S LIST&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td height="70"&gt;&lt;p align="center"&gt;&lt;a href="/ColdStorage/regisbean"&gt;REGISTRATION PAGE&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td height="70"&gt;&lt;p align="center"&gt;&lt;a href="Acceptanceform.jsp"&gt;ACCEPTANCE PAGE&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td height="70"&gt;&lt;p align="center"&gt;&lt;a href="CashReciept.jsp"&gt;CASH RECIEPT&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td height="70"&gt;&lt;p align="center"&gt;&lt;a href="Report.jsp"&gt;REPORT&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td height="70"&gt;&lt;p align="center"&gt;&lt;a href="DetailsTrack.jsp"&gt;TRACK DETAILS&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td height="70"&gt;&lt;p align="center"&gt;&lt;a href="/ColdStorage/resetyear"&gt;RESET YEAR&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;%} else {%&gt;
                  &lt;tr&gt;
                      &lt;td height="70"&gt;&lt;p align="center"&gt;&lt;a href="Report.jsp"&gt;REPORT&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;%}%&gt;
  
  
  
              &lt;/table&gt;
              &lt;p&gt;&amp;nbsp;&lt;/p&gt;
              &lt;p align="center"&gt;
                  &lt;input type="submit" name="signout" id="signout" value="SIGN OUT" onClick="MM_goToURL('parent','Login.jsp');return document.MM_returnValue"&gt;
              &lt;/p&gt;
      &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>