JavaScript Events - markhowellsmead/helpers GitHub Wiki

Block form submission on enter key

Stops the default form submission when pressing the enter key whilst in a form field. In this example, the rule applies to search fields. This can be useful if the search happens amongst page elements, or via an AJAX autocomplete function.

$('input[type="search"]').on('keydown', function(event){
    if (event.keyCode == 13) {
        event.preventDefault();
        return false;
    }
});