title: how to redirect to struts action from java script in struts 2?
body: <p>how to redirect to struts action from java script?</p>
  
  <p>if condition in the script got success then i need to invoke one action in the config xml, otherwise no action invoking the control needs to stay at same page? please help on this?</p>
  
  <p>Java Script</p>
  
  <pre><code>    function displayDate()
  {
  
         var x=document.getElementsByName("userName")
      if(x = "shan")
      {   
      alert("shankarasd");
      document.myForm.action ="/setUpForInsertOrUpdate";
      document.myForm.submit();
      }
  
  }
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>    &lt;html&gt;
          &lt;body&gt;
          &lt;s:form action="HelloWorld" &gt;
              &lt;s:textfield name="userName" label="User Name" /&gt;
              &lt;s:submit onclick="displayDate()" /&gt;
          &lt;/s:form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>config.xml</p>
  
  <pre><code> &lt;struts&gt;
      &lt;package name="default" extends="struts-default"&gt;
          &lt;action name="HelloWorld" class="vaannila.HelloWorld.HelloWorld"&gt; 
              &lt;result name="SUCCESS"&gt;/success.jsp&lt;/result&gt;
          &lt;/action&gt;
          &lt;action name="setUpForInsertOrUpdate" method="setUpForInsertOrUpdate" class="vaannila.HelloWorld.HelloWorld"&gt;
              &lt;result name="SUCCESS1"&gt;/success1.jsp&lt;/result&gt;
          &lt;/action&gt;
          &lt;action name="back" method="back" class="vaannila.HelloWorld.HelloWorld"&gt;
              &lt;result name="SUCCESS2"&gt;/success.jsp&lt;/result&gt;
          &lt;/action&gt;
      &lt;/package&gt;
  &lt;/struts&gt; 
  </code></pre>