title: Trigger form submission with javascript
body: <p>I have a form that I would like to submit via JavaScript. Obviously this can be achieved by:</p>
  
  <pre><code>document.getElementById("myForm").submit();
  </code></pre>
  
  <p>The issue is that I have a listener on the <code>submit</code> event that looks like this:</p>
  
  <pre><code>document.getElementById("myForm").addEventListener("submit", function(event) {
      event.preventDefault();
      // Other work
  });
  </code></pre>
  
  <p>This event handler is not triggered when I call <code>.submit()</code>. From <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit" rel="noreferrer">MDN</a>: </p>
  
  <blockquote>
    <p>The form's onsubmit event handler (for example, onsubmit="return
    false;") will not be triggered when invoking this method from
    Gecko-based applications. In general, it is not guaranteed to be
    invoked by HTML user agents.</p>
  </blockquote>
  
  <p>So, given this restraint, how can I submit the form in a way that ensures the event handler is invoked?</p>