I would like to show an alert on keyup event but only if the key was a letter or a number, not for shift,tab etc.
<input type='text' id='hi />
or for any key except for tab, shift, ctrl, enter
anybody knows how ?
We can use isFinite() on event. key , which will check if event. key is a finite number.
The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, a lowercase "a" will be reported as 65 by keydown and keyup , but as 97 by keypress .
Both are used as per the need of your program and as per the convenience of the user. keyup Fires when the user releases a key, after the default action of that key has been performed. keydown Fires when the user depresses a key.
You will have to attach an "keyup" event to the textbox and inside the event check for the keycodes you want:
$("#hi").bind("keyup", function(e) {
//on letter number
if (e.which <= 90 && e.which >= 48)
{
alert('hello');
}
});
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