in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

HowTo: JavaScript Character Counters for Memo / Text boxes

Last post 11/3/2008 5:55 PM by Mehul Harry (Developer Express). 1 replies.
Page 1 of 1 (2 items)
Sort Posts:
Previous Next
  • 11/1/2008 4:58 PM

    HowTo: JavaScript Character Counters for Memo / Text boxes

    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: ,
  • 11/3/2008 5:55 PM In reply to

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

    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

     

Page 1 of 1 (2 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED