javascript cleanuphtml and maxtextlength

Last post 05-16-2017, 8:04 AM by Kenneth. 6 replies.
Sort Posts: Previous Next
  •  08-31-2010, 4:57 AM 63745

    javascript cleanuphtml and maxtextlength

    How can I use javascript to clean up html code and check the lenght of characters in the editor instead of using the editor function?
  •  08-31-2010, 8:33 PM 63767 in reply to 63745

    Re: javascript cleanuphtml and count number of characters

    I am sorry that my question is not so clear.
     
    In another way, how can I capture the no of  characters shown on the right hand corner  in javascript?
    Can I use javascript function to do the function as same as the editor.CleanupHTML()
  •  08-31-2010, 8:44 PM 63768 in reply to 63767

    Re: javascript cleanuphtml and count number of characters

    Hi surrounding,
     
    1. Clean up HTML example
     
    1. <%@ Page Language="C#" %>   
    2.   
    3. <%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>   
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    5. <html xmlns="http://www.w3.org/1999/xhtml">   
    6. <head id="Head1" runat="server">   
    7.     <title>GetPlainText</title>   
    8. </head>   
    9. <body>   
    10.     <form id="form1" runat="server">   
    11.         <CE:Editor ID="editor1" runat="server">   
    12.         </CE:Editor>   
    13.         <input type="button" value="Clean THML" onclick="cleanTHML()" />   
    14.         <div id="plainText" style="visibility: hidden">   
    15.         </div>   
    16.     </form>   
    17. </body>   
    18. </html>   
    19.   
    20. <script>   
    21. function cleanTHML()   
    22. {   
    23.     var editor1=document.getElementById('<%= editor1.ClientID %>');   
    24.     var plainText=document.getElementById("plainText");   
    25.     plainText.innerHTML=editor1.GetHTML();   
    26.     editor1.SetHTML(plainText.innerText)   
    27.     plainText.innerHTML="";   
    28. }   
    29.   
    30. </script>  
    2. Check the length of the editor text example
     
    1. <%@ Page Language="C#" %>   
    2.   
    3. <%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>   
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    5. <html xmlns="http://www.w3.org/1999/xhtml">   
    6. <head id="Head1" runat="server">   
    7.     <title>GetPlainText</title>   
    8. </head>   
    9. <body>   
    10.     <form id="form1" runat="server">   
    11.         <CE:Editor ID="editor1" runat="server">   
    12.         </CE:Editor>   
    13.         <input type="button" value="Check length" onclick="checkLength()" />   
    14.           </form>   
    15. </body>   
    16. </html>   
    17.   
    18. <script>   
    19. function checkLength()   
    20. {   
    21.     var editor1=document.getElementById('<%= editor1.ClientID %>');   
    22.     alert(editor1.getHTML().length)   
    23. }   
    24. </script>  
    Regards,
     
    ken
  •  08-31-2010, 10:06 PM 63773 in reply to 63768

    Re: javascript cleanuphtml and count number of characters

    The checkLength()  function only show all the characters in the editor.
    If I only want the character without counting the tag code, how can do this?
  •  09-01-2010, 12:47 AM 63775 in reply to 63773

    Re: javascript cleanuphtml and count number of characters

    Hi surrounding,
     
    Try the new example
     
    1. <%@ Page Language="C#" %>   
    2.   
    3. <%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>   
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    5.   
    6.   
    7.   
    8. <html xmlns="http://www.w3.org/1999/xhtml">   
    9. <head id="Head1" runat="server">   
    10.     <title>GetPlainText</title>   
    11. </head>   
    12. <body>   
    13.     <form id="form1" runat="server">   
    14.         <CE:Editor ID="editor1" runat="server">   
    15.         </CE:Editor>   
    16.           <input type="button" value="Get length" onclick="getLength()"/>   
    17.         <div id="plainText" style="visibility: hidden">   
    18.         </div>   
    19.     </form>   
    20. </body>   
    21. </html>   
    22.   
    23. <script>      
    24. function getLength()      
    25. {      
    26.     var editor1=document.getElementById('<%= editor1.ClientID %>');      
    27.     var plainText=document.getElementById("plainText");      
    28.     plainText.innerHTML=editor1.GetHTML();      
    29.     alert(plainText.innerText.length);   
    30.     plainText.innerHTML="";      
    31. }      
    32.      
    33. </script>  
    Regards,
     
    ken
  •  05-16-2017, 3:42 AM 85321 in reply to 63775

    Re: javascript cleanuphtml and count number of characters

    I found that the character count functions are not the same between  

    • (A) Demo one http://cutesoft.net/example/general.aspx
    • (B) the editor that I am using to reply this message
    • (C) My downloaded version (My editor version is 6.7.0.0)
    1. Line break
      (A) Do not count line break
      (B) Count line break
      (C) Do not count line break
    2. Key press
      (A) Will update count after key press 
      (B) Will update count after key press
      (C) Do not update count after key press 

     

    P.S. for the innerText function, it would count the line break also

    I just want to use javascript to get the character count same as the editor one 

  •  05-16-2017, 8:04 AM 85322 in reply to 85321

    Re: javascript cleanuphtml and count number of characters

    Hi,

     

    the forum using another editor "RichTextEditor8.1", is not the same one. You can use the javascript api to get the editor content and get the character count by the javascript code directly.

     

    regards,

     

    Ken 

View as RSS news feed in XML