perform calculation by pressing TAB

1

I am selecting 2 inputs to calculate a value between hours using keypress . My query is how I can perform the calculation only by pressing the% key% of%

$(document).ready(function() {
$('#horaInicio').timepicker({
    'scrollDefault': 'now',
    'timeFormat': 'G:i'
});

$('#horaTermino').timepicker({
    'scrollDefault': 'now',
    'timeFormat': 'G:i'
});

$("#horaTermino").keypress(function(event) {
    ObtieneTotHoras();

})

});

function ObtieneTotHoras() {
  var contar = 0;
  HDesde = $('#horaInicio').val();
  HHasta = $('#horaTermino').val();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="" id="horaInicio" value=""> <br>
<input type="text" name="" id="horaTermino" value="">

<script src="https://cdn.jsdelivr.net/npm/[email protected]/jquery.timepicker.js"></script>
    
asked by MoteCL 23.07.2018 в 16:56
source

1 answer

2

I do not understand very well what you want to do. But specifically when pressing tab lose the focus if you are standing in input.

I could take advantage of this and perform the calculation by losing the focus of that input. If you already want to do it with a key.

You could get the Ascii key of the letter and in an If validate it with the Ascci value of the tab key which is 9

$("#horaTermino").keypress(function(event) {
   if(event.keyCode==9)
   // ObtieneTotHoras();

})
    
answered by 23.07.2018 / 17:11
source