title: Setting the value of a hidden variable on button click and then Submit the Form using .submit() jquery struts
body: <p>I have a problem with Form Submit in struts.
  Setting the value of a hidden variable on button click and then Submit the Form using <code>.submit()</code> jquery is not allowing to show the sucess message in the same page in struts.</p>
  
  <p>when the button is clicked, before the form is submited I need to set a hidden variable from the click of the button and then the form is to be submitted.
  I am able to submit the form using the below code but not in the same popup. </p>
  
  <pre><code>&lt;div id="formResult" &gt;
    &lt;s:form id="formId" name="form"&gt;
      &lt;s:hidden id="actionId" name="action"&gt;&lt;/s:hidden&gt;
      &lt;table cellpadding="0" cellspacing="0" border="0" width="90%" &gt;
        &lt;s:if test ="approve"&gt;
          &lt;tr&gt;
            &lt;td&gt;File is Approved!!&lt;/td&gt;
            &lt;td&gt;&lt;td&gt;
          &lt;/tr&gt;
        &lt;/s:if&gt;           
        &lt;s:elseif test ="rejectFile"&gt;
          &lt;tr&gt;
            &lt;td&gt;File is Rejected!&lt;/td&gt;
            &lt;td&gt;&lt;td&gt;
          &lt;/tr&gt;
        &lt;/s:elseif&gt;           
        &lt;s:else&gt;
          &lt;tr&gt;
            &lt;td width="30%"&gt;&lt;b&gt;&lt;s:text name="idLabel" /&gt;&lt;/b&gt;&lt;/td&gt;
            &lt;td width="40%"&gt;&lt;s:property value="Id"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;div style="height:5px"&gt;&lt;/div&gt;&lt;/td&gt;
            &lt;td&gt;&lt;div style="height:5px"&gt;&lt;/div&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
        &lt;/s:else&gt;
        &lt;tr&gt;
          &lt;td width="90%" colspan="2" align="right"&gt;
            &lt;s:if test="!approveFileSuccess"&gt;
              &lt;sj:a 
                id="approvefileId" 
                onclick="approveFunction();"                      
                button="true"
                targets="formResult"&gt;
                Approve
              &lt;/sj:a&gt;
            &lt;/s:if&gt;                       
            &lt;s:if test="!rejectFileSuccess"&gt;
              &lt;sj:a 
                id="rejectfileId" 
                onclick="rejectFunction();"               
                targets="formResult" 
                button="true"&gt;
                Reject
              &lt;/sj:a&gt;
            &lt;/s:if&gt;
      &lt;/table&gt;
    &lt;/s:form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>JQUERY</strong>:</p>
  
  <pre><code>function approveFunction(){
    $('#actionId').val("Approve");
    document.formId.submit();
  }
  
  function rejectFunction(){
    $('#actionId').val("Reject");
    document.formId.submit();
  }
  </code></pre>
  
  <p>When <code>document.formId.submit();</code> is clicked form submit takes the popup to another page. Not able to show success in the same page.</p>