Javascript - How can I retrive the Character count?

Last post 10-22-2009, 4:41 PM by ethanmcdonald. 4 replies.
Sort Posts: Previous Next
  •  10-09-2009, 10:15 AM 56278

    Javascript - How can I retrive the Character count?

    I can see the Character count listed in the bottom but cannot figure out how extract that number.
    I've tried a regex filter but it's usually off 5 characters or so to what is being displayed in the bottom bar.
  •  10-09-2009, 12:47 PM 56281 in reply to 56278

    Re: Javascript - How can I retrive the Character count?

    Please use the following method to extract the html code from editor. Then get the count of this string.
     
    getHTML()

    This method is used for retrieving the content of CuteEditor as HTML.

    Example:

    // get the cute editor instance
    var editor1 = document.getElementById('CE_Editor1_ID');

    // retrieving the content of Cute Editor as HTML
    var content = editor1.getHTML();
    alert(content );

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  10-09-2009, 4:20 PM 56286 in reply to 56281

    Re: Javascript - How can I retrive the Character count?

    I guess I didn't explain myself very well I went down the 'getHTML' route.  :)

    function chkTxtLength() {
        reTag = /(<([^>]+)>)/ig;
        contentVar = editor1.getHTML();
        contentVar = contentVar.replace(reTag, "");
        return contentVar.length;
    }

    The number outputted by the above function is usually off by about 5 characters give or take.
    I figure why reinvent the wheel, the character count is sitting in the right lower right hand corner.
    That had to come from somewhere, how do retrieve it or what's the regex they use?
  •  10-22-2009, 12:01 PM 56598 in reply to 56286

    Re: Javascript - How can I retrive the Character count?

    Actually this turns out to be 1000 for characters off in the right copy and paste situation.
     
    Once again how can it just pull the value that is already calculated in the bottom corner?
     
    Getting and RegEx-ing  to get an already rendered count seem stupid.
     
    Any ideas how to do this right? 
  •  10-22-2009, 4:41 PM 56606 in reply to 56598

    Re: Javascript - How can I retrive the Character count?

    Back to my solo conversation I figured out another way to do it...
     
    function getCount() {
    var cnt = getElementsByClass('CharCount',document.getElementById("CE_Editor1_ID"),"span");
    cnt = (cnt[0].innerHTML.replace("Characters:","")*1)
    alert(cnt+100);
    }

    function getElementsByClass(searchClass,node,tag) {
            var classElements = new Array();
            if ( node == null )
                    node = document;
            if ( tag == null )
                    tag = '*';
            var els = node.getElementsByTagName(tag);
            var elsLen = els.length;
            var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
            for (i = 0, j = 0; i < elsLen; i++) {
           if ( pattern.test(els[i].className) ) {
               classElements[j] = els[i];
               j++;
           }
            }
            return classElements;
    }
     
View as RSS news feed in XML