jquery keypress event object keyCode for firefox problem?
11,644
Solution 1
You should use e.charCode
in Firefox.
$("#booter").keypress(function(e){
var code = e.charCode || e.keyCode;
var input = $(this).val() + String.fromCharCode(code);
$('#text').focus().val(input);
return false;
});
Try it here:
PS If you're wondering why all this mess: http://www.quirksmode.org/js/keys.html
Solution 2
It works for both IE & FF.
$(document).ready(function (){
$('#txtEntry').keypress(function (e) {
$('#lnkValidEdit').focus();
return false;
});
Related videos on Youtube
Author by
Mr Coder
Programming != Coding . Trying to start Zend Framework development stack ? use my docker stack a simple LAMP/WAMP/XAMPP replacement . https://github.com/krishjun/zf-docker
Updated on October 16, 2020Comments
-
Mr Coder over 3 years
jQuery keypress event for FireFox gives encrypted
keyCode
property for event object afterString.fromCharCode(e.keyCode)
conversion but works perfect in Chrome.Following is the javascript code:
<!-- #booter and #text are ids of html element textarea --> <script type="text/javascript"> $(function(){ $('#booter').keypress(function(e){ var input = $(this).val() + String.fromCharCode(e.keyCode); $('#text').focus().val(input); return false; }); }); </script>
-
Palak Patel almost 8 yearsWorked like a charm... Thanks :)
-
Jasmeen about 7 yearse.charCode || e.keyCode <= This is Perfect :)
-
Mattijs over 6 yearsJust be aware that according to MDN e.keyCode and e.charCode and e.which are deprecated. I was a bit amazed by that since the replacement, called e.code doesn't have proper support. It seems to only option now is e.key which has IE9 support