Introduction:
Here I will explain how to set maximum length of textarea in jQuery or check maximum length of textarea in jQuery.
Description:
In previous articles I explained jQuery disable right click on images, jQuery expand textbox on focus , jQuery slideup slidedown slidetoggle example, jQuery fadein or fadeout example, jQuery create rounded corners for textbox, jQuery show time in webpage and many articles relating to JQuery. Now I will explain how to check maxmimum length of textarea in jQuery.
In previous articles I explained jQuery disable right click on images, jQuery expand textbox on focus , jQuery slideup slidedown slidetoggle example, jQuery fadein or fadeout example, jQuery create rounded corners for textbox, jQuery show time in webpage and many articles relating to JQuery. Now I will explain how to check maxmimum length of textarea in jQuery.
To
implement this we need to write the code like as shown below
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Check count of textarea</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js">
</script>
<script type="text/javascript">
$(function()
{
$('#btnCheck').click(function() {
var txt = $('#txtdesc').val();
if (txt.length > 50) {
alert('Please
enter less than 50 characters')
}
});
})
</script>
</head>
<body>
<div>
<table>
<tr>
<td>
<b>Enter Text:</b>
</td>
<td>
<textarea cols="20" id="txtdesc" rows="2" ></textarea>
</td>
</tr>
<tr>
<td></td>
<td> <input type="button" id="btnCheck" value="Check Length" />
</td>
</tr>
</table>
</div>
</body>
</html>
|
Demo
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
2 comments :
great man!!!!!!
This is very basic right?, instead of if this we can achieve throw textbox keypress event that would be professional manner, :) suggestion
Note: Only a member of this blog may post a comment.