w3resource

onkeypress, onkeydown, onkeyup event attributes of HTML elements

onkeypress

onkeypress attribute of an HTML element initiates some action predefined in a script associated with it, when the user presses the key on the element.

For all of the examples and syntax, we have used abbr element.

Syntax

<abbr onkeypress="some_script | calling some script">text content</abbr> 

Supported elements

All elements but APPLET, BASE, BASEFONT, BDO, BR, FONT, FRAME, FRAMESET, HEAD, HTML, IFRAME, ISINDEX, META, PARAM, SCRIPT, STYLE, TITLE.

Example of using onkeypress

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of using onkeypress</title>
<script type="text/javascript">
function w3r_abbr_onkeypress(){
alert("Thanks for visiting w3reource.");
}
</script>
</head>
<body>
<p>Even after three months of the devastating flood in Pakistan, people are still without food, shelter or hope; <abbr title="British Broadcasting Corporation" onkeypress="w3r_abbr_onkeypress()">BBC</abbr> reports.</p>
</body>
</html>

Result

Onkeypress HTML attribute

View this example in a separate browser window

Example of onkeypress attribute

onkeydown

onkeydown attribute of HTML abbr element initiates some action predefined in a script associated with it, when the user pressed a key and yet to release it, on the element.

Syntax

<abbr onkeydown="some_script | calling some script">text content</abbr> 

Supported elements

All elements but APPLET, BASE, BASEFONT, BDO, BR, FONT, FRAME, FRAMESET, HEAD, HTML, IFRAME, ISINDEX, META, PARAM, SCRIPT, STYLE, TITLE.

Example of using onkeydown

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of using onkeydown</title>
<script type="text/javascript">
function w3r_abbr_onkeydown(){
alert("Thanks for visiting w3reource.");
}
</script>
</head>
<body>
<p>Even after three months of the devastating flood in Pakistan, people are still without food, shelter or hope; <abbr title="British Broadcasting Corporation" onkeydown="w3r_abbr_onkeydown()">BBC</abbr> reports.</p>
</body>
</html>

Result

Onkeydown HTML attribute

View this example in a separate browser window

Example of onkeydown attribute

onkeyup

onkeyup attribute of HTML abbr element initiates some action predefined in a script associated with it, when the user presses the mouse button on the content of the element.

Syntax

<abbr onkeyup="some_script | calling some script">text content</abbr> 

Supported elements

All elements but APPLET, BASE, BASEFONT, BDO, BR, FONT, FRAME, FRAMESET, HEAD, HTML, IFRAME, ISINDEX, META, PARAM, SCRIPT, STYLE, TITLE.

Example of using onkeyup

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of using onkeyup</title>
<script type="text/javascript">
function w3r_abbr_onkeyup(){
alert("Thanks for visiting w3reource.");
}
</script>
</head>
<body>
<p>Even after three months of the devastating flood in Pakistan, people are still without food, shelter or hope; <abbr title="British Broadcasting Corporation" onkeyup="w3r_abbr_onkeyup()">BBC</abbr> reports.</p>
</body>
</html>

Result

Onkeyup HTML attribute

View this example in a separate browser window

Example of onkeyup attribute