First of all Sorry, I don't know what to call those keys (ENTER, F1, HOME, etc).
Actually, I'm creating an input search box which onkeyup calls a function. When the user has input at least two keys my function is called and relevant search results are displayed using AJAX. The problem is when the user presses arrow key, HOME, END, etc then also my ajax is called which I don't want. And pressing F5 key to reload the page when focused on the input don't reloads the page, instead calls the AJAX, that's why it's a big issue for me.
$('input[name=\'search\']').on(keyup, function(e) {
if ($('input[name=\'search\']').val().length >= 2) {
// call ajax to display results..
}
});
I want to add an extra expression in the if
, that checks if the non-visible key is pressed or not. Like -
if ($('input[name=\'search\']').val().length >= 2 && (EXPRESSION FOR VISIBLE KEYS)) {
// call ajax to display results..
}
If any visible key is pressed then ajax is called, else its not.
I don't know how to achieve this. As I cannot do e.keycode == '65'
for each keys like A,B,C,\,=,+,1,2,3,etc
Is there a ready made library to check this or any other way to do this? Please help me.