Why the KeyCode does not work in Chrome

2

The function keyCode does not work in Chrome but Firefox works very well, by pressing the Tab in the input calcular you should trigger the function.

here my code:

$("#calcular").keypress(function(event) {
  var keycode = event.keyCode;
  console.log(event.keyCode);
    if (keycode == 9) {
      $("input[name=Comentarioo]").focus();
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="calcular" value="">

I hope you have explained me well.

    
asked by MoteCL 25.07.2018 в 17:52
source

1 answer

3

To achieve what you want, you can use the keydown method like this:

 $("#calcular").keydown(function(event) {
          var keycode = event.keyCode;
          
            if (keycode == 9) {

                $("input[name=Comentarioo]").focus();
            }

        })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="calcular" value="">

  
    
answered by 25.07.2018 / 17:56
source