Talen Kylon
Talen Kylon

Reputation: 1968

Appending to a text area followed by a new line

I'd like to append a string to a text area, followed by a new line.

My research shows that Here's what I've tried thus far, but have not had any luck with:

function putStr(str){
    document.getElementById('output').value += str +\n;
}


function putStr(str){
    document.getElementById('output').value += str \n;
}

function putStr(str){
    document.getElementById('output').value += str;
    document.getElementById('output').value += \n;
}

Thanks!

Upvotes: 0

Views: 49

Answers (2)

Tyler McGinnis
Tyler McGinnis

Reputation: 35276

put your new line in a string, since it's not a variable.

function putStr(str){
    document.getElementById('output').value += str + '\n';
}

Upvotes: 1

Dean Whitehouse
Dean Whitehouse

Reputation: 894

Give this a go with the quotes

function putStr(str){
   document.getElementById('output').value += str +"\n";
}

JS Fiddle: http://jsfiddle.net/DeanWhitehouse/xk4W3/

Upvotes: 1

Related Questions