Languages
[Edit]
EN

HTML - oninput event (input event)

0 points
Created by:
Isaiah89
361

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>

References

  1. HTMLElement: input event - Web APIs | MDN
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join