I have a simple form to upload a file. If I use the regular submit button, everything works as expected:
<form id="mainform" method="post" action="/" enctype="multipart/form-data"> ... <input type="submit" id="submit" value="Analyze File"/> </form>
But if I change it to a regular button and use Javascript to submit the form, nothing happens:
<input type="button" id="submit" value="Analyze File" onclick="document.getElementById('mainform').submit()"/>
I checked that the onclick handler is indeed called and the form search is working correctly. For example, if I changed it to onclick="alert(document.getElementById('mainform').action)"
, the warning will appear as expected and display the destination URL of the form. But for some reason, calling submit () just doesn't submit the form.
source share