0

My textbox is declared thus:

<asp:TextBox ID="txtShowManyItemTag" CssClass="price" onkeydown="return txtShowManyItemTagKeyUp(this);" TabIndex= "997" runat="server" Text="" Width="50px"   /> 

The javascript function called is:

function txtShowManyItemTagKeyUp(txt) {
    if (window.event.keyCode == 13 && txt.value != '') {
        var nextRow = $(txt).closest('tr').next();
        if (nextRow.length > 0) {
            $(txt).closest('tr').next().find(".price").select();
        }
        else {
            $("#<%=btnOkMany.ClientID %>").select();
        }

        return false;
    }
}

In Chrome and IE, the window.event.keyCode == 13 correctly detects the Enter key being pressed, but I have been unable to find the equivalent for Firefox. Note that I am not passing an event, I'm passing the control that's triggering the event, and I can find no way to get the key code from that object. I'm going through stack overflow, but have not yet found something that matches this situation.

Thanks!

  • Possible duplicate of [window.event.keyCode how to do it on Firefox?](https://stackoverflow.com/questions/6116933/window-event-keycode-how-to-do-it-on-firefox) – Frank Witte Aug 23 '18 at 15:02

1 Answers1

0

Instead of the onkeydown attribute, use

$("#txtShowManyItemTag").on('keydown', txtShowManyItemTagKeyUp);

And declare the function as

function txtShowManyItemTagKeyUp(e) { ... }

Inside it, you can now use e to refer to the event, and this to refer to the <input>.