<html>
<body>
<p>This example demonstrates how to assign an "onkeypress" event to an input element.</p>
<p>Press a key inside the text field to set a red background color.</p>
<input type="text" id="demo" onkeypress="myFunction()">
<script>
function myFunction() {
document.getElementById("demo").style.backgroundColor = "red";
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onkeypress_html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 21 Dec 2022 17:39:59 GMT -->
</html>