Is anybody else having problems with the keyup
event in iOS 9 not firing?
Just a simple test bed replicates the issue for me.
<input id="txtInput" />
Vanilla JS:
document.getElementById('txtInput').onkeyup = function () {
console.log('keyup triggered');
}
jQuery:
$('#txtInput').on('keyup', function () {
console.log('keyup triggered');
});
Neither fire...
I suggest using the
keypress
event on browsers with touch screens. I know that you can't really detect touch screen screens, though, so it leaves you with a few options that your situation will likely dictate.keyup
andkeypress
. This would likely be dependent on how much processing is going on and if you are getting double-fires in some browsers.change
.Either way, you end up with two event listeners.
It's not pretty, but a work around is to bind to
keydown
to capture which key has been pressed, andinput
if you want to obtain the value, including the key typed:If you type 'a' the following occurs:
keydown
fires.e.keyCode
is set to the ASCII value of the key pressed.this.value
is''
(i.e. the same before 'a' has been typed).input
fires.e.keyCode
isundefined
.this.value
is'a'
.You can also manually trigger an
input
event if the enter (13) key is pressed;input
isn't fired by this key by default.