title: javascript continuous after form.submit() method called
body: <p>When a <code>Asp.Net aspx</code> page on my site loads, a Javascript script runs a check on some condition, and if that condition is met, it should set an input element's value programmatically, and then submit the form, also programmatically, using form.submit(). With this, I am not using a <code>click</code> or <code>submit</code> event. The form should be processed backend and then the page reloaded with the correct data (and it does this correctly).</p>
  <p>For some reason, this seems to work fine in FireFox, but it behaves differently in Chrome.</p>
  <p>What is does in Firefox is that after the <code>form.submit()</code> the page reloads and my Javascript gets kicked off from the start (running the check again), as expected.</p>
  <p>However, on Chrome, it seems that after the <code>form.submit()</code> call, the Javascript just continuous with the remaining Javascript code.
  I tried the <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/requestSubmit" rel="nofollow noreferrer">form.requestSubmit()</a>, but that didn't change it.</p>
  <p>My code:</p>
  <pre><code>// check if someCondition is true, if so, a form field needs to be set prgrammatically and then the form submitted. If condition is false, just continue
  if(someCondition){
     VerifyBeforeCheck();
  }
  
  DoTheNextThingIfConditionIsFalse(); //In Firefox, if VerifyBeforeCheck() is fired/ reached, this code never gets executed. In Chrome it will, but I don't want that.
  
  // simple wrapper function, because SubmitMyForm gets called from different events and methods.
  function VerifyBeforeCheck() {
      let newValue = sessionStorage.getItem(&quot;ItemFromSessionStorage&quot;);
      let fld = document.getElementById(&quot;formInputField&quot;); // grabs an &lt;input&gt; field
      field.value = newValue; // used in backend
      SubmitMyForm();
  }
  
  
  function SubmitMyform(){
      let form = document.getElementById('myForm');
      form.submit();
  }
  </code></pre>
  <p>Is this indeed unexpected behavior or am I missing something? I want the situation in Chrome to be as it is currently when I run it in Firefox: After the submit method, the form is submitted and then a page reload. If I need to use a preventDefault, how can I do this, without the event?</p>