Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript enter key pressed event alternative for mobile site

I have a quickfeedback widget in my site which has only one textbox. When user presses enter key, the feedback is automatically sent using ajax. But this doesn't work in mobile devices like android, j2me and so on. Is there any alternative that works in both desktop and mobile? Adding a submit button is not acceptable for me.

like image 803
Jasir KT Avatar asked May 01 '13 11:05

Jasir KT


People also ask

What can I use instead of charCode?

Note: The charCode property is deprecated. Use the key property instead. The charCode property returns the Unicode character code of the key that triggered the onkeypress event.

Does keypress work on mobile?

It works on computers, but not on mobile..

What is e keyCode === 13?

Keycode 13 is the Enter key.

What can I use instead of keyCode JavaScript?

Note: The keyCode property is deprecated. Use the key property instead.


2 Answers

I just checked on android, when you type something and press "Go" (enter alternative?) it will trigger an event and the key code is actually 13 so the same as Enter on desktop keyboards.

Edit:

I'd suggest debugging the code and checking whether the submit is actually triggered but maybe the key code isn't always 13? Just guessing..

Edit2:

Test this code on your mobile. When I press "Go" the input value changes to "sent!" which proves that it works.

like image 170
Adaz Avatar answered Oct 09 '22 20:10

Adaz


Why not use onblur in combination with enter key? If one can press enter, it'll work as is. If one can't, they'll just leave input and then onblur will do work.

like image 29
Ale Avatar answered Oct 09 '22 21:10

Ale