You do not need to use form.submit() ever. Do it right ( onsubmit ) or use click() in the submit button.
Performing this action ...
I canβt come up with a good reason for automatically representing the visible form. To send data without user use, use XMLHttpRequest or WebSockets .
The form is submitted through user interaction (for example, by clicking the submit button), so there is no need to use JavaScript to submit the form. Most likely, you need JavaScript to prevent form submission by returning false to the onsubmit event onsubmit .
... or use click()
To programmatically invoke HTML5 validation (as well as any onsubmit JavaScript event handlers attached to the form), you can invoke the click() function of the submit button that belongs to the form.
If the form does not have a submit button, you can create a temporary one:
var form = document.getElementById("mc-embedded-subscribe-form"); var button = document.createElement('input'); button.type = 'submit'; button.style.display = 'none'; form.appendChild(button); button.click();
Forms with multiple submit buttons must have name attributes so that the server can determine which button the user clicked on. You can 'click' to use these buttons with form.buttonName.click() .
source share