title: form.submit() not working
body: <p>I need to do something to use the ruby cgi to output something.
  As such form must be submitted first followed by the js to alter the element values.
  Using the form.submit() does not work in my case.</p>
  
  <p>Using the simple below example below to output the click me values after submitting the form.
  When the form.submit() function is run,the js will not work on click me.</p>
  
  <p>Form onsubmit method cannot be used as it calls the javascript function first before submitting the form(Must submit the form first then call the JS function to carry out something)</p>
  
  <p>Any idea to resolve this:
  NOTE:MUST SUBMIT FIRST
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).on('click','#afterbutton',function() {
      var form = document.getElementById("myForm");
      //form.submit();
      document.getElementById("test").innerHTML = "afterbutton";
      
      });
      
       $(document).on('click','#beforebutton',function() {
      var form = document.getElementById("myForm");
      //form.submit();
      document.getElementById("test").innerHTML = "beforebutton";
      
      });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;form id="myForm"&gt;
       &lt;input type="submit" value="formSubmitbutton" id="submit"&gt;&lt;br&gt;
       &lt;button id="beforebutton"&gt;beforebutton&lt;/button&gt;&lt;br&gt;
       &lt;/form&gt;
       &lt;button id="afterbutton"&gt;afterbutton&lt;/button&gt;&lt;br&gt;
       &lt;p id="test"&gt;click me&lt;/p&gt;</code></pre>
  </div>
  </div>
  </p>