How can I disable on the keyboard the button "enter"

I simple question, how can I disable the the button “enter” on the keyboard for the search bar?
The user should have only the opportunity to click on the result.

1 Like

Hey there, I think the easiest would be to catch the event and stop its propagation.

It looks like it has been pretty much well covered here: javascript - jquery disable form submit on enter - Stack Overflow

In addition to e.preventDefault(); I would also add e.stopPropagation();

Let me know if that works.

1 Like

Hi Ray,

I see…

$('#formid').on('keyup keypress', function(e) { var keyCode = e.keyCode || e.which; if (keyCode === 13) { e.preventDefault(); return false; } });

How do I find #formid?

I have the same question. I use Algolia with WordPress, and want to disable the “enter” feature. I do not want to use any search page at all, only the autocomplete feature.

Does someone have any suggestion?
If you refer to a code, I will appreciate additional information on where to put the code :slight_smile: (I’m not good at codes – that’s why I use WordPress).

Well, this worked out pretty good! :smile:

<script type="text/javascript">
window.addEventListener('keydown',function(e){if(e.keyIdentifier=='U+000A'||e.keyIdentifier=='Enter'||e.keyCode==13){if('INPUT'&&'text'){e.preventDefault();return false;}}},true);
1 Like