CKTIS / HTML
oninput — handling the input event
The oninput attribute contains JavaScript that runs for the input event. On a text field, it lets you respond to user edits without waiting for the user to leave the field.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
oninput="JavaScript statements"oninput is an event handler content attribute for input, available on all HTML elements. Its value is a JavaScript function body, not merely an event name or a function declaration. Availability of the attribute does not mean that every element generates these events itself.
On a text field, input signals user edits to the value, such as typing, pasting, or deleting text. Unlike change, it does not wait for the edit to be committed, which for a text field usually happens when focus leaves the field. Assigning to value in JavaScript does not automatically fire input.
Inside the attribute code, this refers to the element handling the event, and event provides the event object. There is also a JavaScript property, element.oninput: assigning a function replaces the existing function for that handler; assigning null disables it.
The example copies the current this.value into the result element's textContent. Content Security Policy (CSP) can block inline code; running this example requires inline event handlers to be allowed.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>oninput example</title>
<label>Text: <input type="text" oninput="document.getElementById('result').textContent = this.value"></label>
<p>Value: <output id="result"></output></p>
</html>Result
Value: abc
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.