Forums

HowTo: JavaScript Character Counters for Memo / Text boxes

Last post 11/3/2008 5:55 PM by Mehul Harry (DevExpress). 1 replies.
Sort Posts: Previous Next
  • Andrew MacNeill

    HowTo: JavaScript Character Counters for Memo / Text boxes

    11/1/2008 4:58 PM
    • Top 500 Contributor
    • Joined on 9/23/2008
    • Posts 80

    I had to do this for a client so I thought I would share it.

    Here's some code to create a character counter for your text/memo boxes.

    Note: I used KeyUp because TextChanged only fires when you LEAVE the control.

    Note the use of GetText() to get the content. I struggled (stupidly!) with this trying to use the Javascript s.text property.  The controls have their own javascript methods. GetText and SetText.

    <dxe:ASPxMemo ID="txtInfo" runat="server" Width="100%" Height="76px">
                    <ClientSideEvents KeyUp="function(s,e){
                    var ele = s.GetText();
                    lblInfo.SetText(ele.length + '/4000 characters left');}" />
                    </dxe:ASPxMemo>
    <dxe:ASPxLabel ID="ASPxLabel1"  ClientInstanceName="lblInfo"  runat="server" Text="(maximum 4000 chars)">
                    </dxe:ASPxLabel>

     

    Hope you find it useful. If you have another way, please post it!

     

    Filed under: ,
  • Mehul Harry (DevExpress)

    Re: HowTo: JavaScript Character Counters for Memo / Text boxes

    11/3/2008 5:55 PM
    • Top 10 Contributor
    • Joined on 12/7/2006
    • California
    • Posts 3,350

    Hey Andrew,

    Thanks for posting this solution, I'm sure others will find it useful. Btw, there is also a codecentral sample which you may find useful:

    http://www.devexpress.com/Support/Center/e/E393.aspx

     

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.