Monday, 24 February 2014

Count Number of Character in Multiline Textbox - Part II


Count Number of Character in Multiline Textbox - Part II


This post is the continuation of the Previous Post. We are trying to achieve a similar functionality using an alternative method.

Note: This is a Cross Browser Compatible Approach[Tested in IE,FF and Chrome].

Code Snippet:


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

<!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>Count Number of Character Multiline Textbox II</title>
    <script type="text/javascript" language="Javascript">
        //Character count script!
        function textCounter(field, countfield, maxlimit) {
            if (field.value.length > maxlimit)
                field.value = field.value.substring(0, maxlimit);
            else
                countfield.value = maxlimit - field.value.length;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="uxCommentsNoTextbox" runat="server" Height="100" Width="550" Wrap="true"
           TextMode="MultiLine" onkeyup="textCounter(uxCommentsNoTextbox, this.form.uxCommentsCharCount, 1500);"
           onkeydown="textCounter(uxCommentsNoTextbox, this.form.uxCommentsNoCharCount, 1500);" />
           <br />
           <br />
           <input readonly="readonly" type="text" id="uxCommentsNoCharCount" name="uxCommentsNoCharCount"
       size="4" maxlength="4" value="" style="border: solid 0px white; background: white;" />
    </div>
    </form>
</body>
</html>

No comments:

Post a Comment

Thank You for Your Comments. We will get back to you soon.

back to top