Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending a javascript variable to an html textarea

I know this has to be be doable, does anyone know how and if you can do it?

like image 929
Guyver Avatar asked Dec 13 '22 17:12

Guyver


2 Answers

or you can do it this way:

var myVar = 'sup fresh our turn baby!';
var myTextArea = document.getElementById('myArea');
myTextArea.innerHTML += myVar;
like image 51
KJYe.Name Avatar answered Dec 31 '22 11:12

KJYe.Name


Something like this should work:

var textArea = document.getElementById("mytextarea"); // assuming there is a textarea with id = mytextarea
var textToAppend = document.createTextNode("Hello, World!");
textArea.appendChild(textToAppend);

EDIT: or, as Pointy suggested, the last two lines can be replaced by:

textArea.value += "Hello, World!";
like image 38
Greg Avatar answered Dec 31 '22 10:12

Greg