clear editor1 using javascript

Last post 02-06-2011, 10:13 PM by Eric. 3 replies.
Sort Posts: Previous Next
  •  01-10-2011, 1:32 PM 65658

    clear editor1 using javascript

    Is there a way to clear the editor using javascript?  I have the following javascript but its not working.  Thanks for any help.
     
     function ClearEmailTextbox()
       {  
       document.getElementById('ctl00$ContentPlaceHolder1$Editor1').value = "";
       } 
     
    Below is the vb.net codebehind
                Editor1.Attributes.Add("OnFocus", "ClearEmailTextbox()")
     
  •  01-10-2011, 4:12 PM 65662 in reply to 65658

    Re: clear editor1 using javascript

    Dear lonnie,
     
    Please try the following code:
     
    function clearEditor()
       {
        // get the cute editor instance
        var editor1 = document.getElementById('<%=Editor1.ClientID%>');    
        // Set the editor
        editor1.setHTML("");
       }
     
    Thank you for asking
  •  01-14-2011, 8:44 AM 65724 in reply to 65662

    Re: clear editor1 using javascript

    Thanks Eric for your response.  I'm still having a little trouble in running the javascript.  Here's what the client would like to do.
     
     
    The client would like a "Click here to type message" in the editor when it first appears.  When the user clicks the editor they want the message to disappear.    The editor does not appear when the page loads.  It will only display when the user selects the required fields.
     
    I'm using the following line of code to set an attribute for the editor  but I don't believe onfocus is a method of the editor
     
                Editor1.Attributes.Add("onFocus", "clearEditor()")
     Thanks again for all your help,
    Lonnie 
  •  02-06-2011, 10:13 PM 66089 in reply to 65724

    Re: clear editor1 using javascript

    Dear lonnie,
     
    Please refer to the following snippet:
    <%@ Page Language="C#"%>
    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
    <html>
    <head>
        <title>ASP.NET WYSIWYG Editor - Carriage Return Example</title>  
    </head>
    <body>
        <form id="Form1" runat="server">
            <table cellpadding="15">
                <tr>
                    <td>
                        <br />
                        <CE:Editor id="Editor1"  ThemeType="Office2007"
                            Height="300" Autoconfigure="Simple" runat="server" />
                        <br />                  
                    </td>
                </tr>
            </table>
        </form>
    </body>
    </html>
    <script type="text/javascript">
        function CuteEditor_OnInitialized(editor) {
            var editor1 = document.getElementById("<%= Editor1.ClientID %>");
            var editdoc = editor1.GetDocument();
            if (editdoc.body.addEventListener) {
                editdoc.addEventListener("focusin", clearContent, false);
            }
            else {
                editdoc.onfocusin = function () {
                    clearContent();
                }
            }
        }
        function clearContent() {
            var editor1 = document.getElementById("<%= Editor1.ClientID %>");
            var text = editor1.getHTML();
            if (text == "Click here to type message") {
                editor1.SetHTML("");
            }
        }         
    </script>
    <script runat="server">
        void Page_Load(object sender, System.EventArgs e)
         {
            if (!IsPostBack)
            {
                Editor1.Text = "Click here to type message";
            }    
        }    
    </script>
    Thank you for asking
    Eric@cutesoft.net 
View as RSS news feed in XML