Prev Demo
JavaScript
>
How To Execute A Function When Key Is Pressed On The Element In Javascript?
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Onkeypress</h1> Enter your name: <input type="text" name="txtName" id="txtName" onkeypress="CallFunction(this.id)" /> <input type="button" id="btn" name="btn" value="Submit" /> <p>The text in the textbox is: <label id="lblText"></label> </p> <script> function CallFunction(id) { document.getElementById("lblText").innerHTML = document.getElementById(id).value; } </script> <p><strong>Note:</strong> Enter the text in the textbox, so that same text will aper on the webpage automatically.</p> </body> </html>
Note: We DO NOT save your trial code in our database.
Output