Skip to content

Instantly share code, notes, and snippets.

@thedineshj
Created November 2, 2018 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedineshj/fa2e260bc3d9771b9bf4d265155ed851 to your computer and use it in GitHub Desktop.
Save thedineshj/fa2e260bc3d9771b9bf4d265155ed851 to your computer and use it in GitHub Desktop.
Javascript prevent default form submit
<!DOCTYPE html>
<html>
<head>
<title> Javascript prevent default form submit </title>
</head>
<body>
<form id="form" action="home.php" method="post">
<label for="username">User name</label>
<input name="username" type="text" id="username" />
<button type="submit">Submit</button>
</form>
<script>
let form=document.getElementById('form');
form.onsubmit=function(){
alert("FORM SUBMIT PREVENTED");
return false;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment