On the client side, how to obtain plain text (like serverside's editor.PlainText) that DOES include whitespace entered by the user

Last post 12-23-2009, 4:58 AM by Kenneth. 1 replies.
Sort Posts: Previous Next
  •  12-22-2009, 3:45 PM 57902

    On the client side, how to obtain plain text (like serverside's editor.PlainText) that DOES include whitespace entered by the user

    Using
    innerText(document.getElementById(ID_OF_EDITOR).GetDocument().body) gets the text with html tags stripped out, but also strips carriage returns.  I DO NOT WANT to strip whitespace, but WANT to strip HTML tags.  Is there a way to do this that returns the same result as the server side Editor.PlainText property??
     
    My current idea is to get the editor.getHTML and use a regular expression replace to knock out everything that looks like an html tag, but I'm wondering if there is a better solution.
     
    Thanks,
  •  12-23-2009, 4:58 AM 57907 in reply to 57902

    Re: On the client side, how to obtain plain text (like serverside's editor.PlainText) that DOES include whitespace entered by the user

    Hi robertandrews,
     
    Try this way
     
    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 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="GetPlainText" onclick="GetPlainText()" />   
    14.         <div id="plainText" style="visibility: hidden">   
    15.         </div>   
    16.     </form>   
    17. </body>   
    18. </html>   
    19.   
    20. <script>   
    21. function GetPlainText()   
    22. {   
    23.     var editor1=document.getElementById('<%= editor1.ClientID %>');   
    24.     var plainText=document.getElementById("plainText");   
    25.     plainText.innerHTML=editor1.GetHTML();   
    26.     alert(plainText.innerText);   
    27.     plainText.innerHTML="";   
    28. }   
    29. </script>  
    Regards,
     
    ken
View as RSS news feed in XML