javascript add on keypress code example
Example 1: html onkeypress
<input type="text" onkeypress="myFunction()">
Example 2: adding event listener keypress event in javascript
let msg = document.getDocumentById('#message');
msg.addEventListener("keydown", (event) => {
// handle keydown
});
msg.addEventListener("keypress", (event) => {
// handle keypress
});
msg.addEventListener("keyup", (event) => {
// handle keyup
});