2

We are running PhoneGap 2.6 on Android 3.22 (also jquery mobile and backbone are also in the mix). We want to make it so the user can tap the enter key to submit a form after entering a value in a field. The field is a numeric input.

<input id="myfield" type="number">

Unfortunately, the enter button on the soft keyboard appears to be disabled. So when you tap it, no event is fired. None of the following work:

$('#myfield').on('keyup', keyhandler);
$('#myfield').on('keydown', keyhandler);
$('#myfield').on('keypress', keyhandler);
$('#myfield').keyup(keyhandler);
$('#myfield').keydown(keyhandler);
$('#myfield').keypress(keyhandler);

keyhandler: function(e) {
    console.log('You tapped a key');
    if (e.keyCode  == 13) {
        console.log('You tapped ENTER! Yay!');
    }
}

Is there a way to enable the enter button on a numeric keyboard?

Rusty
  • 213
  • 1
  • 3
  • 10
  • show us the `keyHandler` function. – krishwader Aug 07 '13 at 02:25
  • Have you found a solution? I have been looking at the same problem, and it appear as if number-fields automatically switches the Go-button to a next button, which for some weird reason do not trigger any keydown, keyup or keypress event. I found this [answer nr 2](http://stackoverflow.com/questions/6545086/html-why-does-android-browser-show-go-instead-of-next-in-keyboard), but did not get it to work. – jedimorten Aug 15 '13 at 12:27
  • We never found a solution. We had to back off of using the numeric keypad if we wanted have one of the events fire. – Rusty Nov 15 '13 at 00:45

1 Answers1

2

Not sure if this relates to your problem... but you can simulate form submit similar to what happens when you click on 'Go' via a press via the 'Next' button on a numeric keyboard. You can detect the next keyboard press by using the following bind in JQuery:

$('input').on('keydown', function(e){
    if(e.which === 9) {
        //your code here
    }
});

The 'next' button emulates the tab keypress event on a keyboard, which is key code 9. Unfortunately, keypress and keyup events do not detect the next key event, so you need to bind it on keydown.

Rum Jeremy
  • 502
  • 4
  • 15