<!DOCTYPE html>
<html lang="en-US">
<body>
<p>'myFunction' is triggered when you press a key inside the input field.</p>
<input type="text">
<script>
var x = document.getElementsByTagName("input")[0];
function myFunction(){
alert("You pressed a key inside the input field");
}
x.onkeydown = myFunction;
</script> </body>
</html>