Home > Code > Ajax Controls > Retrieve length of the Text area while user types in text area using JavaScript.

Retrieve length of the Text area while user types in text area using JavaScript.

by Thamil   on Jun 30, 2011   Category: Ajax Controls   |  Views: 1003    |  Points: 25   |  Gold 


Below is a simple JavaScript code snippet shows how to display length of the text area while user types in text area

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm5.aspx.cs" Inherits="WebApplication1.WebForm5" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org
/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Sample-Display length of the textarea</title>

<script type="text/javascript">

function DisplayLength(obj)
{
document.getElementById("txtlength").innerHTML = '(' + obj.value.length + ')';
}

</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<textarea id="summary" runat="server" style="width: 400px; height: 100px;" onkeyup="DisplayLength(this);"></textarea> <asp:Label
ID="txtlength" runat="server" Text=""></asp:Label>

</div>
</form>
</body>
</html>




Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts