Created
February 1, 2016 15:29
-
-
Save Swatto/f5d082dead25dcafbfdc to your computer and use it in GitHub Desktop.
Why forms, why
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> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>Why forms, Why!</title> | |
</head> | |
<body> | |
<form> | |
<input type="text" autofocus> | |
<button>Button</button> | |
</form> | |
<script type="text/javascript"> | |
// Prevent the page to change when the form is submited | |
document.querySelector('form').addEventListener('submit', function(ev) { | |
ev.preventDefault(); | |
}); | |
// Listen to click event on the button to display an alert | |
document.querySelector('button').addEventListener('click', function(ev) { | |
alert('button clicked'); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More information here: https://html.spec.whatwg.org/multipage/forms.html#implicit-submission