I want to make a live preview of input elements in HTML with the JavaScript. Like when use will write something in the field, it will automatically print the text under the field. So how can I make it? I have tried to make it in different ways. But every time I got undefined.
const showCase = document.querySelector('#Message')
const field = document.querySelector('#Field')
field.addEventListener('keyup', () => {
field.addEventListener('keypress', () => {
showCase.innerHTML = this.value
})
})
You can try something like below.
const myInput = document.getElementById('input'); // Input Element with id="input" const myOutput = document.getElementById('output'); // An empty paragraph with id="output"