Another way to get the desired result:
window.mostrarTexto= function(valor){
var campo = document.getElementById("campo").value;
div.innerHTML = campo;
}
<input id="campo" type="text" onkeyup="mostrarTexto(this.value)"/>
<div id="div" style="display:block"></div>
The difference this way with the one presented by @Alexsander and basically the event that calls the function
onkeyup
-> function is triggered when the user releases a key
oninput
-> function is triggered when the element receives a user input
It is worth remembering that oninput
and an attribute added to HTML5
which may hinder its use in older browsers...
Please select the answer that solved or helped you solve the problem, choose the best answer helps the next people who have the same question.
– user3603