How to Stop Form Submission in Browser Using JavaScript preventDefault() Event Method Full Project For Beginners

 

Welcome folks today in this blog post we will be stopping form submission in browser using javascript preventdefault() event method All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to make a index.html file and copy paste the following code

 

 

index.html

 

 

<form id="user-form" action="process.php" method="post">
  First name: <input type="text" name="first_name" id="first_name"><br/>
  Last name: <input type="text" name="last_name" id="last_name"><br/>
  Phone number: <input type="text" name="phone_number" id="phone_number"><br/>
  <input type="submit" id="submit-btn">
</form>
<script>
document.getElementById("submit-btn").addEventListener("click", function(event){
  event.preventDefault()
});
</script>

 

Leave a Reply