I'm trying to debug a webpage and I see a form element whose opening is
<form name="aspnetForm" method="post" action="default.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm">
Having only a base knowledge of web form
s, I'm wondering what the order of execution is for the action
and onsubmit
.
The onsubmit event is an event that occurs when you try to submit a form. You can put your form validation against this event type. The following example shows how to use onsubmit. Here we are calling a validate() function before submitting a form data to the web server.
The action attribute is used to specify where we want to send the form data when the form is submitted. So the value of the action is the page that will process the form.
It means that do nothing on submit.
Definition and Usage The onsubmit event occurs when a form is submitted.
If action
was resolved first, then the browser would leave the page, the JS execution environment would go away, and there would be nowhere to run the JS in onsubmit
, so it isn't.
Event handlers run before default actions. They can cancel default actions.
The onsubmit
must execute first, as returning false from it stops the form being submitted, and thus the action
ever being requested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With