Wednesday, December 11, 2013

Count Remaining Characters in TextBox Using JavaScript.

Today I am going to explain How can you Count Remaining Characters in TextBox Using JavaScript.
Basically this program is use for sending SMS.
Demo : 

Now Copy the Code and Paste in .aspx Page


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="harddiskdetails.aspx.cs" Inherits="harddiskdetails" %>

<!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 id="Head1" runat="server">
    <title></title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var characterLimit = 140;
        $(document).ready(function () {
        $("#ReChar").html(characterLimit);
        $("#TextBox1").bind("keyup", function() {
                var characterInserted = $(this).val().length;
                if (characterInserted > characterLimit) {
                    $(this).val($(this).val().substr(0, characterLimit));
                }
                var characterRemaining = characterLimit - characterInserted;
                $("#ReChar").html(characterRemaining);
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
 
    <div align="center"><pre class="code"
             
            style="background-color: white; border: 6px solid rgb(234, 234, 234); color: #444444; font-family: 'courier new'; font-size: 13px; line-height: 18px; outline: rgb(212, 212, 212) solid 1px; overflow: auto; padding: 15px; position: relative; text-align: center; width: 494px; top: 0px; left: 0px; height: 503px;"><asp:Image
                ID="Image2" runat="server" ImageUrl="~/dotnetlogo.png" Width="303px"
            Height="73px" />

<label id="ReChar" style="color:Red;font-weight:bold"></label><label> characters remaining.</label>            
     <asp:TextBox ID="TextBox1" runat="server" Height="77px" TextMode="MultiLine"
            Width="245px"></asp:TextBox>      
           
              <asp:Image ID="Image1" runat="server" Height="39px" ImageUrl="~/dotnet6.png"
                Width="314px" />  </pre></div>
    <div>
        <br />
    </div>
    </form>
</body>

</html>


1 comment: