<input type="text" id="txt"> <script> document.getElementById("txt").onkeydown = function (e) { e = e || event; alert(e.CharCode + " " + e.keyCode); } </script>