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?

3
  • show us the keyHandler function. Commented Aug 7, 2013 at 2: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, but did not get it to work. Commented Aug 15, 2013 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. Commented Nov 15, 2013 at 0:45

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.