jquery keypress event object keyCode for firefox problem?

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">        
            var input = $(this).val() + String.fromCharCode(e.keyCode);
            return false;



You should use e.charCode in Firefox.

     var code = e.charCode || e.keyCode;
     var input = $(this).val() + String.fromCharCode(code);
     return false;

Try it here:


PS If you're wondering why all this mess: http://www.quirksmode.org/js/keys.html


It works for both IE & FF.

 $(document).ready(function (){

         $('#txtEntry').keypress(function (e) {

             return false;



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.