I'm trying to prevent certain keys from being entered into an input box, but only if that particular key is pressed whilst the shift key is held:
$('selector').keydown(function(e) {
console.log(e.shiftKey);
if (e.shiftKey && e.which == 51) {
e.preventDefault();
alert('Disallowed');
}
});
The alert fires but the character still appears in the text box.
I've tried searching around for an explanation as to why this happens but to no avail, any help would be greatly appreciated!
edit
Removing the alert
seems to fix the problem (which seems bizarre), I'd really love to know why it behaves in this way though, it doesn't seem to make any sense.
Thanks