Reputation: 91
I have code in javascript which get keycodes of different keys and set it to hidden field. Hidden field is then manipulated by server side code. My code is:
function TriggeredKey(e) {
e = e || window.event;
var keycode;
if (window.event){
keycode = event.which ? window.event.which : window.event.keyCode;
}
alert(keycode);
document.getElementById("<%=hdfkey.ClientID %>").value = keycode;
_dopostback();
}
This code works fine in Chrome but not in Mozilla. Can someone please provide me the solution for this problem?
Upvotes: 1
Views: 4281
Reputation: 4696
function TriggeredKey(e) {
e = e || window.event;
var keycode;
if (window.event){
//this check fails in mozilla/
//so the variable keycode is undefined
keycode = event.which ? window.event.which : window.event.keyCode;
}
if(!keycode){keycode = e.which}
//solves the issue
alert(keycode);
document.getElementById("<%=hdfkey.ClientID %>").value = keycode;
_dopostback();
}
Upvotes: 2