In JavaScript, using the addEventListener()
method:
object.addEventListener("keyup",
myScript);
This example uses the addEventListener()
method to attach a "keyup" event to an input element.
Press a key inside the text field and release it to set a red background color.
<!DOCTYPE html> <html> <body> Enter your name: <input type="text" id="fname"> <script> document.getElementById("fname").addEventListener("keyup", myFunction); function myFunction() {//from w w w .j a va2 s .c om var x = document.getElementById("fname"); x.value = x.value.toUpperCase(); } </script> </body> </html>
Bubbles: Cancelable: Event type: Supported HTML tags: | Yes Yes KeyboardEvent All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> |
---|