Adding javascript variable to html textarea

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

+3
source share
4 answers

or you can do it like this:

var myVar = 'sup fresh our turn baby!';
var myTextArea = document.getElementById('myArea');
myTextArea.innerHTML += myVar;
+6
source

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 Walkney suggested, the last two lines can be replaced with:

textArea.value += "Hello, World!";
+3
source
function appendText(str) {
var obj=document.getElementById("myTextArea")
var txt=document.createTextNode("append this text")
obj.appendChild(txt)
}
+2
source

The guys said:

document.getElementById('whatever').value += someJavascriptString;
+1
source

Source: https://habr.com/ru/post/1780523/


All Articles