Have you ever faced a situation where you wanted to execute a function you want instead of sending the form data when the form submit button is clicked. This post describes one way you can do just that. This behavior is very useful in tasks like form data validation. We don’t want to send form data to server if the data validation fails.
Code snippets
Assume your form has the following structure,
You can override the default form submission behavior by using a JavaScript function like below for the form’s onsubmit event. Here the usage of “e.preventDefault()” function is important to avoid form data submission.