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?
javascript jquery mobile click keyup
add a comment |
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?
javascript jquery mobile click keyup
add a comment |
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?
javascript jquery mobile click keyup
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?
javascript jquery mobile click keyup
javascript jquery mobile click keyup
asked Aug 17 '16 at 6:31
user1374796user1374796
80193569
80193569
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
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
add a comment |
There are three events you can use (but you have to be careful on how you "combine" them):
keyup : it works on devices with a keyboard, it's triggered when you release a key (any key, even keys that don't show anything on the screen, like ALT or CTRL);
touchend: it works on touchscreen devices, it's triggered when you remove your finger/pen from the display;
input: it's triggered when you press a key "and the input changes" (if you press keys like ALT or CTRL this event is not fired).
The input event works on keyboard devices and with touchscreen devices, it's important to point this out because in the accepted answer the example is correct but approximative:
test.on('keyup input', function(){
}
On keyboard based devices, this function is called twice because both the events keyup and input will be fired.
The correct answer should be:
test.on('keyup touchend', function(){
}
(the function is called on keyup for desktops/laptops OR on touchend for mobiles)
or you can just simply use
test.on('input', function(){
}
but remember that the input event will not be triggered by all keys (CTRL, ALT & co. will not fire the event).
add a comment |
The touchend event is fired when a touch point is removed from the device.
https://developer.mozilla.org/en-US/docs/Web/Events/touchend
You can pass keyup and touchend events into the .on() jQuery method (instead of the keyup() method) to trigger your code on both of these events.
test.on('keyup touchend', function(){
//code
});
add a comment |
You should add a input event. It works on both mobile and computer devices.
It would be good to add more information to your response. See the FAQ and try to update your answer
– GMB
Dec 9 '18 at 18:04
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38989559%2fjquery-keyup-event-for-mobile-device%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
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
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
edited May 23 '17 at 11:46
Community♦
11
11
answered Aug 19 '16 at 5:49
JoysonJoyson
2,26811025
2,26811025
add a comment |
add a comment |
There are three events you can use (but you have to be careful on how you "combine" them):
keyup : it works on devices with a keyboard, it's triggered when you release a key (any key, even keys that don't show anything on the screen, like ALT or CTRL);
touchend: it works on touchscreen devices, it's triggered when you remove your finger/pen from the display;
input: it's triggered when you press a key "and the input changes" (if you press keys like ALT or CTRL this event is not fired).
The input event works on keyboard devices and with touchscreen devices, it's important to point this out because in the accepted answer the example is correct but approximative:
test.on('keyup input', function(){
}
On keyboard based devices, this function is called twice because both the events keyup and input will be fired.
The correct answer should be:
test.on('keyup touchend', function(){
}
(the function is called on keyup for desktops/laptops OR on touchend for mobiles)
or you can just simply use
test.on('input', function(){
}
but remember that the input event will not be triggered by all keys (CTRL, ALT & co. will not fire the event).
add a comment |
There are three events you can use (but you have to be careful on how you "combine" them):
keyup : it works on devices with a keyboard, it's triggered when you release a key (any key, even keys that don't show anything on the screen, like ALT or CTRL);
touchend: it works on touchscreen devices, it's triggered when you remove your finger/pen from the display;
input: it's triggered when you press a key "and the input changes" (if you press keys like ALT or CTRL this event is not fired).
The input event works on keyboard devices and with touchscreen devices, it's important to point this out because in the accepted answer the example is correct but approximative:
test.on('keyup input', function(){
}
On keyboard based devices, this function is called twice because both the events keyup and input will be fired.
The correct answer should be:
test.on('keyup touchend', function(){
}
(the function is called on keyup for desktops/laptops OR on touchend for mobiles)
or you can just simply use
test.on('input', function(){
}
but remember that the input event will not be triggered by all keys (CTRL, ALT & co. will not fire the event).
add a comment |
There are three events you can use (but you have to be careful on how you "combine" them):
keyup : it works on devices with a keyboard, it's triggered when you release a key (any key, even keys that don't show anything on the screen, like ALT or CTRL);
touchend: it works on touchscreen devices, it's triggered when you remove your finger/pen from the display;
input: it's triggered when you press a key "and the input changes" (if you press keys like ALT or CTRL this event is not fired).
The input event works on keyboard devices and with touchscreen devices, it's important to point this out because in the accepted answer the example is correct but approximative:
test.on('keyup input', function(){
}
On keyboard based devices, this function is called twice because both the events keyup and input will be fired.
The correct answer should be:
test.on('keyup touchend', function(){
}
(the function is called on keyup for desktops/laptops OR on touchend for mobiles)
or you can just simply use
test.on('input', function(){
}
but remember that the input event will not be triggered by all keys (CTRL, ALT & co. will not fire the event).
There are three events you can use (but you have to be careful on how you "combine" them):
keyup : it works on devices with a keyboard, it's triggered when you release a key (any key, even keys that don't show anything on the screen, like ALT or CTRL);
touchend: it works on touchscreen devices, it's triggered when you remove your finger/pen from the display;
input: it's triggered when you press a key "and the input changes" (if you press keys like ALT or CTRL this event is not fired).
The input event works on keyboard devices and with touchscreen devices, it's important to point this out because in the accepted answer the example is correct but approximative:
test.on('keyup input', function(){
}
On keyboard based devices, this function is called twice because both the events keyup and input will be fired.
The correct answer should be:
test.on('keyup touchend', function(){
}
(the function is called on keyup for desktops/laptops OR on touchend for mobiles)
or you can just simply use
test.on('input', function(){
}
but remember that the input event will not be triggered by all keys (CTRL, ALT & co. will not fire the event).
edited Aug 31 '18 at 23:25
Benjamin
15.9k29122231
15.9k29122231
answered Feb 28 '18 at 12:33
FrankFrank
3981510
3981510
add a comment |
add a comment |
The touchend event is fired when a touch point is removed from the device.
https://developer.mozilla.org/en-US/docs/Web/Events/touchend
You can pass keyup and touchend events into the .on() jQuery method (instead of the keyup() method) to trigger your code on both of these events.
test.on('keyup touchend', function(){
//code
});
add a comment |
The touchend event is fired when a touch point is removed from the device.
https://developer.mozilla.org/en-US/docs/Web/Events/touchend
You can pass keyup and touchend events into the .on() jQuery method (instead of the keyup() method) to trigger your code on both of these events.
test.on('keyup touchend', function(){
//code
});
add a comment |
The touchend event is fired when a touch point is removed from the device.
https://developer.mozilla.org/en-US/docs/Web/Events/touchend
You can pass keyup and touchend events into the .on() jQuery method (instead of the keyup() method) to trigger your code on both of these events.
test.on('keyup touchend', function(){
//code
});
The touchend event is fired when a touch point is removed from the device.
https://developer.mozilla.org/en-US/docs/Web/Events/touchend
You can pass keyup and touchend events into the .on() jQuery method (instead of the keyup() method) to trigger your code on both of these events.
test.on('keyup touchend', function(){
//code
});
answered Aug 17 '16 at 6:35
user5116395
add a comment |
add a comment |
You should add a input event. It works on both mobile and computer devices.
It would be good to add more information to your response. See the FAQ and try to update your answer
– GMB
Dec 9 '18 at 18:04
add a comment |
You should add a input event. It works on both mobile and computer devices.
It would be good to add more information to your response. See the FAQ and try to update your answer
– GMB
Dec 9 '18 at 18:04
add a comment |
You should add a input event. It works on both mobile and computer devices.
You should add a input event. It works on both mobile and computer devices.
answered Dec 9 '18 at 17:33
user10643043
It would be good to add more information to your response. See the FAQ and try to update your answer
– GMB
Dec 9 '18 at 18:04
add a comment |
It would be good to add more information to your response. See the FAQ and try to update your answer
– GMB
Dec 9 '18 at 18:04
It would be good to add more information to your response. See the FAQ and try to update your answer
– GMB
Dec 9 '18 at 18:04
It would be good to add more information to your response. See the FAQ and try to update your answer
– GMB
Dec 9 '18 at 18:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38989559%2fjquery-keyup-event-for-mobile-device%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown