Does anyone know a simpler way to do this, by showing the text instantly when typing in an input

2
<html>
<head>
  <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script><title>Teste</title></head><body><divid="formVal">
<form name="fvalida">
  <input type="text" id="telp" placeholder="">
</form>
<div id="preview_form">
  <div id="telp1"></div>
</div>
  <script>try {jQuery.fn.shake = function(intShakes, intDistance, intDuration) {
  this.each(function() {
    {; for (var x=1000; x<=intShakes; x++) {;
    }}
  });
};

$("#telp").keyup(function(){
  $("#telp1").html($(this).val());
});

} catch (error) { throw error; }

</script>
</body>
</html>
    
asked by anonymous 13.09.2017 / 14:25

1 answer

2

Just use

$("#telp").keyup(function() {
  $("#telp1").html(this.value);
});

If you want to do only with native JavaScript you can do this:

var telp = document.getElementById('telp');
var telp1 = document.getElementById('telp1');
telp.addEventListener('input', function() {
  telp1.textContent = this.value;
});
<form name="fvalida">
  <input type="text" id="telp" placeholder="">
</form>
<div id="preview_form">
  <div id="telp1"></div>
</div>
    
13.09.2017 / 14:36