Monday, August 27, 2012

jquery – Detect entered character with JavaScript

I\’d like to start an action (enabling autocomplete) when user types \’@\’. However I don\’t know how to do it correctly. I have jQuery available.


Usually on a QWERTY keyboard, it is like this:



$(\'textarea\').live(\'keydown\', function(e) {
if (e.which === 50) {
console.log(\'@ has been entered.\');
}
});


However it does not work correctly on an AZERTY keyboard. The keyCode = 50 corresponds to the é~/2 key. To type \’@\’ in AZERTY keyboard, it is AltGr + à@/0 key.


Edit: I was not clear. Autocomplete starts when @ is entered, and only after that. Example, when someone enters \”Hello @\” then it starts, however when he types \”Hello @nothing else\” the complete won\’t do anything. Example: http://mrkipling.github.com/jQuery-at-username/ (it works only on QWERTY keyboard).






Rating: 2 out of 5 based on 4 ratings



The post jquery – Detect entered character with JavaScript appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/jquery-detect-entered-character-with-javascript.html

No comments:

Post a Comment