js press key on input code example
Example 1: javascript enter event listener
document.querySelector('#txtSearch').addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
// code for enter
}
});
Example 2: html onkeypress
<input type="text" onkeypress="myFunction()">