You should (in some styling opinions) declare your function before using it in your event listener, although all browsers will hoist this, it will give you errors if you use jslint though.
'doKeyDown' was used before it was defined.
Here is one of many answers giving information of the above: JSLint: Using a function before it's defined error
Here is an example, on jsfiddle
<input id="input" type="text"></input>
console.log("W", "W".charCodeAt());
function logIt(evt) {
console.log(String.fromCharCode(evt.charCode), evt.charCode);
}
var input = document.getElementById("input");
input.addEventListener("keypress", logIt, false);
You may also want to take a read of the following answer, there are others, regarding different event types keypess
and keydown
, and the properties charCode
and keyCode
:
JavaScript KeyCode vs CharCode