This event will be fired when user enter an input. This event is mostly used with the input and textareat elements. This event is similar to onchange event. But there is a bit difference between them, oninput event will fired after the value of a element has changed, while onchange event will be fired when element loses it focus.
Example :
HTML Code :
<!DOCTYPE html>
<html>
<body>
<input type="text" id="myInput" oninput="oninputFunction()">
<p id="demo"></p>
</body>
</html>
Javascript Code :
<script>
function oninputFunction() {
var x = document.getElementById("myInput").value;
document.getElementById("demo").innerHTML = "You wrote: " + x;
}
</script>
Output :
As you write something in the text box, simultaneously it will display same text (due to oninput event ).
0 Comment(s)