Sử dụng oninput thuộc tính sự kiện để kích hoạt khi một phần tử được người dùng nhập. Bạn có thể thử chạy mã sau để triển khai oninput thuộc tính -
Ví dụ
<!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>