js add value to textarea code example

Example 1: assign value to textarea

Example 2: html set textarea value

// To set the textarea value, you must insert the TEXT into the element.

// javascript
var textarea = ``;
document.getElementById('my_textarea_id').textContent = 'foo'
// php
$value = 'foo';
$textarea = "";
echo $textarea;

Example 3: javascript textarea.append

var $log = $('#myTextArea');

function log(text) {
    $log.append(text);
}

// Call log() in your button click event or whichever function 
// you want to use to print to the text area:

//...
log("Hello world!");
//...

Tags:

Misc Example