Reputation: 37504
I'm trying to disable Enter key submit on a form but allow the Enter key event to be registered for some other code I have listening. Is this possible?
$('#createPost :input').on("keypress", function(e) {
if(e.target.id == 'post-author' && e.which == 13){
e.stopPropagation();
e.stopImmediatePropagation();
}
});
Is not working :( it still submits the form
Upvotes: 0
Views: 621
Reputation: 14304
You need to call e.preventDefault()
to cancel submit action.
return false;
from handler also works. And that works in more ancient browsers, even though this is not important with jQuery.
Upvotes: 1