John Ohara John Ohara - 1 year ago 97
Javascript Question

keydown not firing Chrome on mobile

I have the following code - it's got some temporary alerts in at the moment as I'm trying to get to the bottom of this issue.

The functionality is based around an Asp.Net Textbox and a RequiredFieldValidator. The idea being that when 'enter' is pressed I get the status of the textbox and do something.

Now, here's the strange bits:

If I use a standard type="text" on the textbox - I don't actually add this its just defaulted, it works on all browsers/devices.

By works, I mean if I don't put a valid entry i.e. anything in the textbox, an error should display.

If I use type="tel" or type="number", it works on Firefox and Chrome desktop but not Chrome on mobile.

If I add the alerts in as per the code below, mobile works too.

function enterKeyPressed(e) {
alert("function called");
if (e.which == 13) {
alert("enter pressed");
var isValid =, false);
if (isValid) {
var next =;

Anyone got any idea where I can start?

Answer Source

Here's what worked for me - desktop, mobile and all html5 input types.

function enterKeyPressed(e) {
        if (e.which == "13") {
            // Do something
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download