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:
xxxxxxxxxx
1
<input type="text" oninput="myFunction()">
or using JavaScript:
xxxxxxxxxx
1
input.addEventListener('input', myFunction);
In this example, we create a function that handles input event and we assign the function to the input
element using oninput
attribute.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<script>
5
6
function myFunction(input) {
7
console.clear();
8
console.log("Current input value: " + input.value);
9
}
10
11
</script>
12
</head>
13
<body>
14
<span>Type something to trigger oninput event:</span>
15
<input type="text" id="my-input" oninput="myFunction(this)">
16
</body>
17
</html>