Home  >  Article  >  Web Front-end  >  In HTML, execute a script when an element receives user input?

In HTML, execute a script when an element receives user input?

PHPz
PHPzforward
2023-09-17 14:13:021247browse

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 -

Example

<!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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete