I have a web page where I am using a textbox to get the user’s First name. I am using an onKeyUp handler in it to validate the input for any non-permissible characters and also to check if the user presses the enter key. The textbox is not inside a form.
The input looks like this:
<input type='text' id='userNameBox' onKeyUp='user.checkUserName(event);' />
Here user is the object created from a JavaScript class by name User.
On the webpage, when I click inside the textbox and enter some text, the validation occurs.
The problem I am facing is that I have a console.log in the checkUserName method. It is:
console.log('key pressed='+event.which);
When the focus is in the textbox, some unknown events are getting fired periodically. I keep getting the message key pressed=252 even though I am not pressing any keys. What is the keycode 252 and why is it getting fired on its own? I tried searching for the same but could not get any proper results.
I use Prototype Library in my application.
Here is a full listing of keyCodes, note that it differs by browser.
http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/Note-KeyProps.html
I would recommend against using event.which and use event.keyCode as support for event.which in internet explorer is questionable.