tags:

views:

2142

answers:

2

I'm getting "The 'charCode' property of a keydown event should not be used. The value is meaningless" error in firefox using jQuery. My code looks like this:

$("div#center-box div#empid-textbox input.id").keydown(function(e){
   key = e.which;
   if(key===13){
      //do something;
   };
});

does anyone know how to remedy this error?

A: 

FIXED!!!

Seems like FF is not liking the 'keydown' function...I changed it to 'keypress' and it works perfectly.

sadmicrowave
-1 Only problem is that keypress refuses to work in google chrome. If I use keydown my scripts work in all browsers if I change to keypress it does not so I wouldnt use this solution unless I either only code for firefox or create workarounds for other browsers.Since you did not suggest any alternatives I am downvoting this solution.
mhenrixon
@CatZ - it doesn't seem like you provided much of a solution or suggest any alternatives either. So my comment is at least mildly better than yours (unfortunately I cannot downvote a subcomment).
sadmicrowave
+2  A: 

Check the first comment on http://api.jquery.com/event.which/

I found the same annoying behaviour using jQuery 1.4.2 with Firefox 3.6.3 as well. The fix for me was to remove "charCode" from the list of cloned attributes in line 1956 of jquery-1.4.2.js -- this list contains attributes to be cloned from the original event in the browser to a tailored jQuery event object that is more sane. Reading the "charcode" attribute in the cloning procedure seemed to trigger the warning in the error console. Cloning of the actual attribute, be it "keyCode" or "charCode" seems to be handled fine if lines 1996-1998 are changed to:

if (!event.which && ((originalEvent.charCode || originalEvent.charCode === 0) ? event.charCode : event.keyCode)) {
  event.which = originalEvent.charCode || event.keyCode;
}

i.e. a more delicate cloning of the charCode property if present.

daniel