Keyup events (DOM)

3

The goal is that when writing something in the input, it is also written in the paragraph using onkeyUp. However it does not work

window.addEventListener('load', iniciar, false);

function iniciar() {
  var titulo = document.getElementById('texto').value;
  titulo.addEventListener('onKeyUp', nuevotitulo, false);
}

function nuevotitulo(e) {
  document.getElementById('textonuevo').innerHTML = titulo;
}
<body>
  <input type="text" id="texto">
  <br>
  <p id="textonuevo">
  </p>
</body>
    
asked by Vendetta 09.08.2017 в 17:09
source

1 answer

4

First of all, the event must be attacked at input no at value of input

Second, the event is called keyup no onKeyUp

window.addEventListener('load', iniciar, false);

function iniciar() {
  document.getElementById('texto').addEventListener('keyup', nuevotitulo, false);
}

function nuevotitulo() {
  document.getElementById('textonuevo').innerHTML = document.getElementById('texto').value;
}
<body>
  <input type="text" id="texto">
  <br>
  <p id="textonuevo">
  </p>
</body>
    
answered by 09.08.2017 / 17:20
source