-2

I'm trying to input text into a textarea and have it start on a new line with every insert.

Currently this is my code, so when you enter a username/text and click post it will paste this into a text area.

<script type="text/javascript">

document.getElementById("post").addEventListener('click', function () {

var username = document.getElementById('username').value;
var input = document.getElementById('input').value;
var output = document.getElementById('output');

var outputtext = username + ":" + input;
output.value += outputtext;

});
</script>

currently the output looks like this:

Username1:Text1Username2:Text2Username3:Text3

Where As i want it to display as:

Username1:Text1
Username2:Text2
Username3:Text3

Cheers for any help

Liam
  • 27,717
  • 28
  • 128
  • 190
T.script
  • 297
  • 1
  • 3
  • 13

1 Answers1

6

JUst add the <br> as \nto the string of outputtext:

var outputtext = username + ":" + input +"\n";

\n - a new line character n that must be escaped with backslash \ and encapsulated in double quotation marks "

ino
  • 2,345
  • 1
  • 15
  • 27