views:

643

answers:

1
 $('input').keyup(function(e){
  var k = e.keyCode ? e.keyCode : e.which;          
  console.log(k);  

  });

.

    <input type="text" name=""  autocomplete="off"/>

Why keyup fires twice but only after second strike for special keys (arrows, space, backspace etc) ? - Are any solutions to fix this issue? - the autocomplete it's turned off - In IE it is working fine - With keydown or keypress is working fine for FF and Chrome - But I can't use keypress because it doesn't work for IE for special keys - I can't use keydown because I need the value of the input including the character I just type. Like this $(this).val(); - (I needed it for a live search). Keydown will give the value but without the last char. Maybe you could give me an idea in this direction - how to capture the value including last char with keydown?

A: 

Based on your question I'm a bit confused, will combining keyup and .val() not do what you want?

$('input').keyup(function(e){
  liveSearchFunction($(this).val());
});

If not please elaborate a bit more.

Nick Craver
Yes keyup will give the value that i need (including last char). But when I try to navigate on the result list with up and down arrows, or I press backspace, first stroke will not do nothing and the second stroke will fire twice. (so basically it jumps over one result). Put my code and watch closely for the console result when you push arrows or backspace, enter etc