JavaScript Events
Mark Howells-Mead edited this page Oct 9, 2019
·
1 revision
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;
}
});
Mark Howells-Mead | https://permanenttourist.ch and https://sayhello.ch/ | Wiki since 2016
Use this code freely, widely and for free. Provision of this code provides and implies no guarantee.
Please respect the GPL v3 licence, which is available via http://www.gnu.org/licenses/gpl-3.0.html