Max word count?

Last post 12-09-2010, 10:20 PM by Kenneth. 4 replies.
Sort Posts: Previous Next
  •  12-06-2010, 7:06 PM 65301

    Max word count?

    Is there any way to prevent pasting in or typing in more than a particular maximum number of words in the editor? I am using the editor for classic ASP and can see how to limit characters, but not words. Given that the interface already does a word count, I can't imagine that a maximum word count would be all that hard to do, but I can't see it in the API.
     

    There is only do or not do - there is no try.

    Yoda
    Filed under: , ,
  •  12-06-2010, 8:30 PM 65302 in reply to 65301

    Re: Max word count?

    Hi snips,
     
    Please refer to http://cutesoft.net/forums/thread/63727.aspx
     
    Regards,
     
    Ken
  •  12-06-2010, 9:16 PM 65305 in reply to 65302

    Re: Max word count?

    Thanks Ken, but I am looking for a way to limit words,  not characters. It seems to me that in seraching the forums, I see this coming up all the time and various code based on getHTML seems to be the only solution that appears to be offered. Given how often people need this, you'd think CuteSoft woudl develop a property or method MaxWordLength.
     
    snips
     

    There is only do or not do - there is no try.

    Yoda
  •  12-06-2010, 9:51 PM 65306 in reply to 65305

    Re: Max word count?

    Well, I hope the company considers developing this as a property that can be validated and enforced. In the meantime, I have developed an approach using a javascript onsubmit function:
     

    function getLen(){
    // get the cute editor instance
    var editor1 = document.getElementById('<%=editor.clientID%>');

    // retrieving the content of Cute Editor as HTML
    var content = editor1.getHTML();
    //split the content by spaces to get the array of words
    arWords=content.split(" ");
    //use the length property of the array to count words.
    //Probably should trim any leading or trailing spaces.
    strWordLength="Words: " + arWords.length;
    //this just prints out the length, but you could use it to fail the onsubmit
    alert(strWordLength);
    }
     
    %<
    snips

    There is only do or not do - there is no try.

    Yoda
  •  12-09-2010, 10:20 PM 65344 in reply to 65306

    Re: Max word count?

    Hi snips,
     
    The example below shows you how to get the same count as the right bottom in editor. hope it help.
     
     
    <!-- #include file = "cuteeditor_files/include_CuteEditor.asp" -->
    <html>
        <head>  
     </head>
        <body>  
      <form name="theForm" action="Edithtml.asp?postback=true"  method="post">
      <%      
       Dim editor
       Set editor = New CuteEditor
       editor.ID = "Editor1"  
       editor.MaxTextLength=25
       If request.QueryString("postback") <> "true" then
        editor.Draw()
       else
        editor.SaveFile("document.html")
        editor.Draw()
       End if
                
       ' Request.Form(ID) access from other page
      %>      
        <input type="button" value="GetPlainText" onclick="GetPlainText()" />
            <div id="plainText" style="visibility: hidden">
      </form>
     </body>
    </html>
    <script>



    function isIE() {
        if (window.navigator.userAgent.toLowerCase().indexOf("msie") != -1) return true;
        else return false;
    }

    function GetPlainText() {

        var editor1 = document.getElementById('<%=editor.ClientID%>');
        var plainText = document.getElementById("plainText");
        plainText.innerHTML = editor1.GetHTML();
        var text;
        if (isIE()) {
            text = plainText.innerText;
        }
        else {
            text = plainText.textContent;
        }
        var words = text.replace(/\s+/g, "-").split("-");
        var count = 0;
        for (var i = 0; i < words.length; i++) {
            if (words[i] != "") {
                count++;
            }
        }
        alert(count);
        plainText.innerHTML = "";
    }
    </script>
    Regards,
     
    Ken
View as RSS news feed in XML