In this tutorial we will learn How to Get textarea value with JavaScript. We can use value property along with the getElementById() method to get the value of textarea tag.
Table of Contents
value property
value property sets or returns the value of the HTML input elements.
In this example value property is used to get the value of textarea tag.
getElementById() method
getElementById() method is used to select HTML element by it's id.
In this example getElementById() method is used to select textarea tag.
HTML Code
HTML Code is given below, in this code we have a textarea element and a button tag.
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Get textarea value</title>
</head>
<body>
<textarea id="textarea">This is Textarea Tag!</textarea>
<button onclick="getTextareaValue()">Get Textarea value</button>
<script src="script.js"></script>
</body>
</html>
JavaScript Code
Take a look at the JavaScript code, In this code user defined function getTextareaValue() will get the value of textarea.
textarea value is displayed using alert() method.
<script>
function getTextareaValue()
{
var textarea = document.getElementById('textarea');
var value = textarea.value;
alert(value);
}
</script>
Demo
Video Tutorial
Watch video tutorial on how to Get textarea value using JavaScript.