oninput
A user action changes a control value or editable content. HTML event-handler content attribute or corresponding event-handler property; the event fires only on relevant targets. The example uses document.getElementById("demo"). Event interface: InputEvent / Event. For the described native event: bubbles: yes; cancelable: no. Text editing usually provides InputEvent; other controls may provide Event. Assigning value in JavaScript does not itself fire input. Example: Type into the field; for change, move focus away to commit. The event listener is registered with addEventListener(), which avoids inline script handlers and supports multiple listeners. Inline handlers require a CSP that permits them; do not insert untrusted code into handler attributes.
Formal Syntax & Structure
<input oninput="handleEvent(event)">target.addEventListener("input", event => { /* handle event */ });Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| oninput | JavaScript handler body | Optional HTML event-handler code; the example uses a registered listener instead. Not a Boolean attribute. |
| event | InputEvent / Event | Event object delivered to the addEventListener callback; event.type is "input". Inspect target, currentTarget, bubbles and cancelable as appropriate. |
Working Example
<label for="demo">Sample text</label><input id="demo" value="Example text"><p role="status" id="log">Waiting for input</p><script> const target = document.getElementById("demo"); const log = document.getElementById("log"); target.addEventListener("input", event => { log.textContent = String(event.type + ": " + event.target.value); });</script>