EN
HTML - oninput event (input event)
0
points
In this article, we would like to show you how to use input event in HTML.
Quick solution:
<input type="text" oninput="myFunction()">
or using JavaScript:
input.addEventListener('input', myFunction);
Practical example
In this example, we create a function that handles input event and we assign the function to the input
element using oninput
attribute.
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<head>
<script>
function myFunction(input) {
console.clear();
console.log("Current input value: " + input.value);
}
</script>
</head>
<body>
<span>Type something to trigger oninput event:</span>
<input type="text" id="my-input" oninput="myFunction(this)">
</body>
</html>