Getting key code in Firefox from webforms textbox keydown event
Getting key code in Firefox from webforms textbox keydown event
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!
1 Answer
1
Instead of the onkeydown
attribute, use
onkeydown
$("#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>
.
e
this
<input>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Possible duplicate of window.event.keyCode how to do it on Firefox?
– Frank Witte
Aug 23 at 15:02