Home > Article > Web Front-end > In HTML, execute a script when an element receives user input?
Use oninput Event attribute is triggered when the element gets user input. You can try running the following code to achieve oninput property -
<!DOCTYPE html> <html> <body> <p>Write your name below:</p> <input type = "text" id = "myid" oninput="display()"> <p id="test"></p> <script> function display() { var p = document.getElementById("myid").value; document.getElementById("test").innerHTML = "Your answer is " + p; } </script> </body> </html>
The above is the detailed content of In HTML, execute a script when an element receives user input?. For more information, please follow other related articles on the PHP Chinese website!