Get textarea value in jQuery

textarea value using jQuery

In web applications while using textarea control, we need to get the value of textarea at client side. In this post we will see example of how to get value of textarea in jQuery.

Example to get textarea value in jQuery

<html xmlns="">
<head runat="server">
<script src="development-bundle/jquery-1.7.1.js" type="text/javascript"></script>
<script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
<title>Get textarea value in jQuery</title>
<script type="text/javascript">
$(document).ready(function () {
$("#submitbtn").click(function () {
var textAreaValue = $("#txtMessage").text();
<form id="form1" runat="server">
<textarea cols="50" rows="5" id="txtMessage"></textarea>
<input type="button" id="submitbtn" value="Submit" />


  1. This is not working :(

  2. Instead of
    var textAreaValue = $("#txtMessage").text();
    var textAreaValue = $("#txtMessage").val();

  3. If you use Chrome Browser or want users to be able to use crome you probabli need to add:

    header("X-XSS-Protection: 0");

    Or the XSS protection in Chrome will not execute the script:
    The XSS Auditor refused to execute a script in http://... because its source code was found within the request. The auditor was enabled as the server sent neither an 'X-XSS-Protection' nor 'Content-Security-Policy' header.