I'm trying to make a simple search box. How can I trigger a function just after a single letter was typed in an input box? I used .keyup, but this seems to be useless, because when a diacritic character is typed, the function is triggered three times.
<input id="text" type="text" />
<div></div>
<script>
$('#text').keyup(function(){
$('div').append('TEST'+$(this).val());
});
</script>
The above code works fine unless you type any diacritic character: ą, ś, ł, ż, ź, ć, etc.
I can't use .keypress or .keydown since they trigger a function before a character is typed.
EDITED LATER:
I know that my example might not be clear enough to understand the problem, but... In my real code every time a letter is typed, an SQLite query is executed. If a type a diacritic character or a capital letter, the query is executed three or two times, which slows down the whole script. It won't make a big difference if you execute the script in a computer web browser, but there is significant lag in mobile browsers.
I considered checking the value of the string compared to the last time it was changed. So keypresses don't run the function unless it causes the string to be changed.
http://jsfiddle.net/82sTJ/1/
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