Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

onkeyup — handling key release

The onkeyup attribute contains JavaScript that handles the keyup event after a key is released. It is an HTML global attribute, not a way to detect every change to a field's value.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

onkeyup="JavaScript statements"

onkeyup is an HTML global event handler attribute. Its value contains JavaScript statements, not an event name or a file address. It handles keyup, the event associated with releasing a key.

Inside the attribute code, the event parameter provides the event, and this refers to the element hosting the handler. The onkeyup attribute and the JavaScript property element.onkeyup represent the same handler mechanism; assigning a function to the property replaces the previous handler.

Do not equate keyup with text changes. Releasing a key need not change a value, and editing a control need not involve a keyboard. To respond to user-driven value changes, use the input event.

The example changes a status message when it receives keyup. It requires JavaScript to be enabled and the page's security policy to permit event handlers written in attributes.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>onkeyup demo</title>
<label>Test field
  <input type="text" onkeyup="document.getElementById('result').textContent = 'keyup received'">
</label>
<p id="result" role="status">Waiting</p>
</html>

Result

keyup received

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources