-3

For this code it's work good:

<script type="text/javascript" src="//code.jquery.com/jquery-1.8.3.js"></script>
<textarea style="height: 300px;"></textarea>
<p id="preview"></p>        
<script type="text/javascript">
setInterval(function() {
    $('#preview').html($('textarea').val());
}, 10);
</script>

But when I change from <p> to <input like this:

<script type="text/javascript" src="//code.jquery.com/jquery-1.8.3.js"></script>
<textarea style="height: 300px;"></textarea>
<input type="text" id="preview">
<script type="text/javascript">
setInterval(function() {
    $('#preview').html($('textarea').val());
}, 10);
</script>

Why it's not working? How can I resolve it?

curious
  • 1,504
  • 5
  • 18
  • 32

1 Answers1

1

Use .val instead .html like this:

<script type="text/javascript" src="//code.jquery.com/jquery-1.8.3.js"></script>
<textarea style="height: 300px;"></textarea>
  <input type="text" id="preview">
<script type="text/javascript">
   setInterval(function() {
   $('#preview').val($('textarea').val());
    }, 10);
</script>       
Risa__B
  • 451
  • 4
  • 8