Created
November 2, 2018 14:57
-
-
Save thedineshj/fa2e260bc3d9771b9bf4d265155ed851 to your computer and use it in GitHub Desktop.
Javascript prevent default form submit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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