jQuery keypress event for FireFox gives encrypted keyCode
property for event object
after String.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>
Keycode 13 is the Enter key.
keyCode: Returns the Unicode value of a non-character key in a keypress event or any key in any other type of keyboard event. event. charCode: Returns the Unicode value of a character key pressed during a keypress event.
Introduction to jQuery keycode Key codes are the keyboard keys to which have digital values mapped to the keys based on the key code description. jQuery keycode is a part of Themes in jQuery UI API category, there are many more API's like disableSelection(), enableSelection(), . uniqueId(), . zIndex(), .
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:
http://jsfiddle.net/REJ4t/
PS If you're wondering why all this mess: http://www.quirksmode.org/js/keys.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With