JQuery Textarea

Textarea are used to collect more line of data from users.

Reading the data entered in textarea

Our textarea id=textarea_dtl, here is the code to read the value entered inside a text box.
var str=$('#textarea_dtl').val();
Here we stored the text box data in a variable str.
We can display the data entered by connecting it to a button click function.
Enter some text inside textarea and then Click the button.
HTML part
<textarea rows=2 cols=30 name=textarea_dtl id=textarea_dtl></textarea>
   <button name=b1 id=b1>Copy</button>   <div id=d1></div>
$(document).ready(function() {
var str=$('#textarea_dtl').val();

Adding Bootstrap Design

We will add class='form-control' to our textarea.
<textarea class='form-control' rows=2
  name=textarea_dtl id=textarea_dtl></textarea>

Setting the value of a textarea

We will use val() to update or add text to our textarea. Click the button below.
<textarea rows=2 cols=30 name=textarea_dtl2 id=textarea_dtl2
  class='form-control'></textarea> <button name=b12 id=b12>Show Data</button>

$(document).ready(function() {
$("#textarea_dtl2").val('Default Data to be shown inside textarea');

Disable the textarea

We can disable a textarea or enable it by managing prop
$("#textarea_dt13").prop("disabled", false);
Here the button with id b5 on Click will disable the textarea , same time button with id b6 will enable it by using click event function.

HTML part
<input type=text name=my_text id=t2>
<button name=b5 id=b5>Disable</button> <button name=b6 id=b6>Enable</button> 
$(document).ready(function() {
$("#textarea_dt13").prop("disabled", true);
$("#textarea_dt13").prop("disabled", false);


Length of the string inside textarea

We can get length of the string entered inside a textarea by using length. Here we are reading the string and storing in a variable str. Then we are displaying the length of the string inside a div tag with id=d1.
var str=$('#t1').val();
Reading the number of Chars in a Textarea
Using the above concepts we can develop a script where the submit button will be enabled after entering some minimum number of chars in a textarea.
Here is the sample.
You must enter 10 cars minimum to enable the associated button. Note that we have used keyup event to trigger the code block for calculating and disabling the button.
<textarea name=t123 rows=4 cols=60 id=t123></textarea>
<button id=b123>Send Data</button>
<div id=d123>0</div>
$(document).ready(function() {
  $('#b123' ).prop( 'disabled',true )
// Jquery code here ///
  var str=$('#t123').val();
if(str.length>9){$('#b123' ).prop( 'disabled',false )}
else{$('#b123' ).prop( 'disabled',true)}
To add colour changes to button use css function.


Post your comments , suggestion , error , requirements etc here .

Most Popular JQuery Scripts


Two dependant list boxes


Calendar with Date Selection


Data change by Slider


Show & Hide element

JQuery Video Tutorials

We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer