I want convert following working jQuery code into JavaScript
$(document).ready(function(){
$("#txt1").keydown(function(event){
var keyPress=String.fromCharCode(event.keyCode);
var Keycode=event.keyCode;
alert("KeyPress : "+keyPress)
alert("KeyCode : "+Keycode)
})
})
and I am trying this to replace this code with JavaScript
document.getElementById("txt1").onkeydown=function(event){
var keyPress=String.fromCharCode(event.keyCode);
var Keycode=event.keyCode;
alert("KeyPress : "+keyPress)
alert("KeyCode : "+Keycode)
}
and this above code not working.
document.getElementById("txt1").addEventListener('keydown', function(event) { ... });