revision:
The oninput attribute fires when the value of an <<input> or <textarea> element is changed.
The "oninput attribute" is part of the event attributes, and can be used on any HTML element.
This event is similar to the "onchange event". The difference is that the oninput event occurs immediately after the value of an element has changed, while onchange occurs when the element loses focus. The other difference is that the onchange event also works on <select> element.
<element oninput="script"></element>
value: this attribute contains a script and it works when the oninput event is triggered.
Write something in the text field to trigger a function.
<p class="spec" >Write something in the text field to trigger a function.</p> <input style="margin-left:3vw;" type="text" id="myInput" oninput="myInput()"> <p class="spec" id="demo-A"></p> <script> function myInput() { var x = document.getElementById("myInput").value; document.getElementById("demo-A").innerHTML = "You wrote: " + x; } </script>
Enter some text here:
<p class="spec">Enter some text here: <input type="text" id="demo-1" oninput="addMe()"></p> <p class="spec" id="sudo"></p> <script> function addMe() { var x = document.getElementById("demo-1").value; document.getElementById("sudo").innerHTML = "Entered Text: " + x; } </script>