I have a form like below:
<form action="/action_page.php" onsubmit="alert('The form was submitted');" >
Enter name: <input type="text" name="fname">
<input type="button" onclick="document.getElementsByTagName('form')[0].submit()" value="Submit">
</form>
Though I clicked the button and indeed it submitted the form, but the alert
box wasn't shown. That is, the submit()
method submitted the form but without triggering the onsubmit
event. What happened? And how should I use submit()
method to trigger the onsubmit
event?