LearnFast.Ninja

jQuery get text from textarea

This tutorial show you how to get value from textbox in jQuery. It is recommended that you try for yourself the working example code. In this example we build html textarea and div with click event. When the user click it trigger a javascript function that get text from textbox and show it in alert box.

Step 1: Use the val method.
$('textarea#MessageArea').val();

Working Example Code:

<!DOCTYPE html>

<html>

<head>

    <title>HTML5</title>

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>

    <script type="text/javascript">

        function showText() {

            var message = $('textarea#MessageArea').val();

            alert(message);

        }

    </script>

</head>

<body onload="drawCanvas();">

    <textarea id="MessageArea" rows="2" cols="20" style="width: 200px;"></textarea>

    <div onclick="showText();" style="cursor: pointer;">Show text</div>

</body>

</html>


Result:


Tags

jquery

textarea value val