html tutorial - onkeydown Attribute in HTML - html5 - html code - html form




onkeydown attribute in html

Learn html - html tutorial - onkeydown attribute in html - html examples - html programs

  • The onkeydown attribute fired when the user is pressing a key inside the input field.
  • The onkeydown attribute is an Event Attributes.

Syntax for onkeydown attribute in HTML:

<element onkeydown="script">

Applies To:

Element Attribute
All HTML elements onkeydown

Attribute Values:

Value Description
script The script can run on onkeydown

Sample Coding for onkeydown Attribute in HTML:

Tryit<!DOCTYPE html>
<html>
   <body>
       Enter the text:
       <input type="text" id=” tutorials” onkeydown= "Wikitechy()" >
       <script>
       function Wikitechy() 
       {
         document.getElementById("tutorials").style.backgroundColor ="green";
       }
       </script>
   </body>
</html>

Code Explanation for onkeydown Attribute in HTML:

onkeydown Attribute Code Explanation

  1. <input> tag is used to create a text box for getting an input from the user.
  2. The value of an <input> element's id attribute is tutorials.
  3. onkeydown attribute activate the “Wikitechy()”function when the user press the key on the keyboard.
  4. function Wikitechy() is a JavaScript function (block of code).
  5. style.backgroundColor=”green” is used to change the background color of the text box as green.

Output for onkeydown Attribute in HTML:

onkeydown Attribute Tag Output

  1. The text box will be display on page load.
onkeydown Attribute Tag Output

  1. The text box background color changed as green when the user press a key in the text box.

Browser Support for onkeydown Attribute in HTML:

Yes Yes Yes Yes Yes

Related Searches to onkeydown Attribute in html