Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we capture a mobile device "Next" button key press in Javascript

Most keys on a mobile smartphone keyboard produce a keycode with the following code, however the "Next" and "Prev." buttons do not:

$('#txtRegMobileNumber2').keydown(function (e) {
    alert('Key pressed: ' + e.keyCode);
});

How can I capture the "Next" button press (equivalent to the arrows in iOS) in Javascript?

This other question may be a duplicate, but seeing as how the code does not work for me I still need help. I've tried using e.which and keyup() to no avail.

like image 485
m4gik Avatar asked Mar 05 '15 20:03

m4gik


People also ask

How do you trigger button click on Enter key press using JavaScript?

To trigger a click button on ENTER key, We can use any of the keyup(), keydown() and keypress() events of jQuery. keyup(): This event occurs when a keyboard key is released. The method either triggers the keyup event, or to run a function when a keyup event occurs.

How do you press a key in JavaScript?

To record a keypress event in JavaScript, use the code below: // Add event listener on keypress document. addEventListener('keypress', (event) => { var name = event. key; var code = event.

Can JavaScript simulate key presses?

If you need keyup events too, it is also possible to simulate keyup events by changing "keydown" to "keyup" in the code snippet. This also sends the event to the entire webpage, hence the document . If you want only a specific element to receive the event, you can substitute document for the desired element.

What is e KeyCode === 13?

Keycode 13 is the Enter key.


1 Answers

If you are concerned in capturing when the user moved away from your text field, maybe consider the blur() JavaScript event?

https://developer.mozilla.org/en-US/docs/Web/Events/blur

like image 77
justin.lovell Avatar answered Sep 20 '22 05:09

justin.lovell