Skip to content

Instantly share code, notes, and snippets.

@gerad
Created March 16, 2011 19:47
Show Gist options
  • Save gerad/873172 to your computer and use it in GitHub Desktop.
Save gerad/873172 to your computer and use it in GitHub Desktop.
shows a bug with chrome event handling
<form onsubmit='alert("should not get here");'>
<input id="text" type="text" placeholder="type something and hit enter">
</form>
<script>
var t = document.getElementById('text');
t.addEventListener('keydown', function(e) {
if (e.which === 13) { // hitting return
alert('form submission should be prevented');
e.stopPropagation();
e.stopImmediatePropagation();
e.preventDefault();
}
});
</script>
@gerad
Copy link
Author

gerad commented Mar 16, 2011

if you take out the 'form submission should be prevented' alert, the form submission is prevented

also, see http://jsfiddle.net/86maU/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment