Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: keyup event for mobile device

I'm having a few issues getting a keyup event to fire on my iPhone, my code is as follows:

        var passwordArray = ["word", "test", "hello", "another", "here"];

        var test = document.getElementById('enter-password');
        test.addEventListener('keyup', function(e) {

            if (jQuery.inArray(this.value, passwordArray) != -1) {
                alert("THIS IS WORKING");
            } else {}

        });

The idea being that as the user is typing into the #enter-password field, as and when they've matched a word in the passwordArray the alert will fire. This works on desktop, e.g. once you've entered word the function will fire straight away as soon as you've typed the d. Is there anyway to get this to work for mobile too?

like image 747
user1374796 Avatar asked Aug 17 '16 06:08

user1374796


People also ask

Does Keyup event work on mobile?

It works on both mobile and computer devices.

What is event keyup?

The keyup event is fired when a key is released. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered.

How keyup works?

The keyup event is sent to an element when the user releases a key on the keyboard. It can be attached to any element, but the event is only sent to the element that has the focus. Focusable elements can vary between browsers, but form elements can always get focus so are reasonable candidates for this event type.


1 Answers

You can add input event. It is an event that triggers whenever the input changes. Input works both on desktop as well as mobile phones

test.on('keyup input', function(){
  //code
});

You can check this answer for more details on jQuery Input Event

like image 104
Joyson Avatar answered Sep 17 '22 14:09

Joyson