1

I'm trying to add an event that triggers when the user hits enter in a text input field, to perform a search.

  document.querySelector('input[name="filter-search-tag"]').onkeypress = function(e){
      if (!e) e = window.event;
      var keyCode = e.keyCode || e.which;
      if (keyCode == '13'){
            alert('pressed');
      }
  };

It works perfectly fine on desktop, but on mobile it only works if you hit enter 2 or 3 times. It usually gives 229 as the keycode instead of the proper key. Same thing happens with onkeyup and onkeydown.

Surely there is a way to detect hitting enter on android?

stackers
  • 2,701
  • 4
  • 34
  • 66
  • 2
    check out [THIS](https://stackoverflow.com/questions/36753548/keycode-on-android-is-always-229), looks like you can't detect Enter hit... – snachmsm Feb 02 '23 at 21:45

0 Answers0