javascript get textarea value code example

Example 1: javascript clear text in textarea

// HTML
<textarea id='output' rows=20 cols=90></textarea>
<input type="button" value="Clear" onclick="javascript:eraseText();"> 

// JS
function eraseText() {
    document.getElementById("output").value = "";
}

Example 2: capture textarea value

<textarea id="myTextarea">
Hello World
</textarea>

<script>
  var x = document.getElementById("myTextarea").value;
</script>

Example 3: javascript find textarea

if(document.getElementsByTagName('textarea').length > 0) {

}

Tags:

Html Example