Beyond MaxTextLength ... Real Time Text Characters Remaining Displayed ... Possible?

Last post 04-10-2006, 9:45 PM by smacca. 10 replies.
Sort Posts: Previous Next
  •  09-26-2005, 2:29 AM 11008

    Beyond MaxTextLength ... Real Time Text Characters Remaining Displayed ... Possible?

    I enjoyed the result of using MaxTextLength within the control.
     
    I'd like to look into displaying to a user, in real-time, how many text characters he has remaining before going over the MaxTextLength limit. Perhaps using a Editor1_TextChanged sub with code that displays in a label either characters typed or remaining. Any VB/JavaScript code ideas?
  •  09-26-2005, 1:21 PM 11030 in reply to 11008

    Re: Beyond MaxTextLength ... Real Time Text Characters Remaining Displayed ... Possible?

     
    We show you how to attach the onkeypress event to the editor.

    You can modify this example to meet your own requirements.

     
     

    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

  •  09-26-2005, 4:50 PM 11052 in reply to 11030

    Re: Beyond MaxTextLength ... Real Time Text Characters Remaining Displayed ... Possible?

    After looking at the JavaScript_API page Adam refers to above, the following code displays the number of HTML characters remaining into a textbox in the 6.02.2900 version of IE.

    The 7.2 version of Netscape and the 1.0.6 version of FireFox display an error dialog stating:

        TypeError: editdoc.attachEvent is not a function.

    If you know how to modify the code below to work with FireFox and Netscape, please let me know.

    <script language="JavaScript" type="text/javascript" >
    function CE_attachEvent()
    {
    // get the cute editor instance
    var editor1 = document.getElementById('CE_Editor1_ID');
    //Get the editor content
    var editdoc=editor1.GetDocument();
    // attach Event
    editdoc.attachEvent('onkeypress',HandleChange);
    }
     
    function HandleChange()
    {
    // get the cute editor instance
    var editor1 = document.getElementById('CE_Editor1_ID');
    //Get the editor content
    var editdoc=editor1.GetDocument();
    // alert(editdoc.body.innerHTML.length);
    var totalcharacters = 5000;
    var usedcharacters = editdoc.body.innerHTML.length;
    var txtbx = document.getElementById('txtbox1');
    txtbx.value = totalcharacters - usedcharacters;
    }
    </script>
    <html>
    <body onload="CE_attachEvent()">
     form id="Form1" runat="server">
    <CE:Editor id="Editor1" UseRelativeLinks=true EditorWysiwygModeCss="example.css" RemoveServerNamesFromUrl=true MaxHTMLLength=5001 runat="server" ></CE:Editor><br />
    <asp:Button id="btnUpdate" onclick="Submit" Runat="server" Text="Submit"></asp:Button>&nbsp;
    HTML Characters Remaining: <input id="txtbox1" name="HTMLCharsRemaining" type="text" /><br/><br />
    </form>
    </body>
    </html>
     
  •  09-26-2005, 5:09 PM 11053 in reply to 11052

    Re: Beyond MaxTextLength ... Real Time Text Characters Remaining Displayed ... Possible?

    Please use the following code:
     
    function CE_attachEvent()
       {
        // get the cute editor instance
        var editor1 = document.getElementById('<%=Editor1.ClientID%>');
        
        //Get the editor content 
        var editdoc=editor1.GetDocument();
        // attach Event
        if(editdoc.attachEvent)
         editdoc.attachEvent('onkeypress',HandleChange);
        else if(editdoc.addEventListener)
         editdoc.addEventListener('keypress',HandleChange,true);
       }   
       
       function CE_detachEvent()
       {
        // get the cute editor instance
        var editor1 = document.getElementById('<%=Editor1.ClientID%>');
        
        //Get the editor content 
        var editdoc=editor1.GetDocument();
        // detach Event
        if(editdoc.detachEvent)
         editdoc.detachEvent('onkeypress',HandleChange);
        else if(editdoc.removeEventListener)
         editdoc.removeEventListener('keypress',HandleChange,true);
       }
       
       function HandleChange()
       {
        // get the cute editor instance
        var editor1 = document.getElementById('<%=Editor1.ClientID%>');
        //Get the editor content 
        var editdoc=editor1.GetDocument();
        alert(editdoc.body.innerHTML);
       }  

    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

  •  04-10-2006, 7:19 AM 18051 in reply to 11053

    Re: Beyond MaxTextLength ... Real Time Text Characters Remaining Displayed ... Possible?

    I cannot get this code to work.
    Can anyone identify where I am going wrong!?
    Assume all ID's are correct (I am wiring this in using ClientID property of controls).
     
    ----------------------------------------------------------------------------------------
     
     
    <script language="javascript" type="text/javascript">
    <!--
     //get the cute editor instance
     var editor = document.getElementById("CE_htmlEditor_Editor_ID");
     //Get the editor content
     var editdoc = editor.GetDocument();
     //attach Event
     if(editdoc.attachEvent)
      editdoc.attachEvent("onkeypress", HandleChange);
     else if(editdoc.addEventListener)
      editdoc.addEventListener("keypress", HandleChange, true);
     
    //Q: Is there a way to check the keypress event was registered!???

     function HandleChange()
     {
      window.alert('never gets here!!!!!!!!!!!!');
     }
    //-->
    </script>
     
     
     
     
    ----------------------------------------------------------------------------------------

     

    Stephen McCormack
    MWeb Solutions Pty Ltd
    http://www.mwebsolutions.com.au
  •  04-10-2006, 3:10 PM 18068 in reply to 18051

    Re: Beyond MaxTextLength ... Real Time Text Characters Remaining Displayed ... Possible?

    Stephen,
     
     
    Try the following code:
     
    <body onload="setTimeout(CE_attachEvent,1000);">
     
    function CE_attachEvent()
       {
        // get the cute editor instance
        var editor1 = document.getElementById('<%=Editor1.ClientID%>');
       
        //Get the editor content 
        var editdoc=editor1.GetDocument();
        // attach Event
        if(editdoc.attachEvent)
         editdoc.attachEvent('onkeypress',HandleChange);
        else if(editdoc.addEventListener)
         editdoc.addEventListener('keypress',HandleChange,true);
       }
     
    Keep me posted
     
     
     

    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

  •  04-10-2006, 9:09 PM 18083 in reply to 18068

    Re: Beyond MaxTextLength ... Real Time Text Characters Remaining Displayed ... Possible?

    Suggestion: I realise it is probably another advertising forum here for your product but the FULL CONFIG toolbar when making a post takes a long time to load. Can I suggest you simply limit the tools here to RICHTEXT ONLY (bold, italic) and insert other likes Hyperlink. Just a suggestion!?

    Stephen McCormack
    MWeb Solutions Pty Ltd
    http://www.mwebsolutions.com.au
  •  04-10-2006, 9:18 PM 18084 in reply to 18083

    Re: Beyond MaxTextLength ... Real Time Text Characters Remaining Displayed ... Possible?

    Please use the minimal configuration.
     
     
    The following article shows you how to create your own layout of toolbars.
     
    How to change the layout of the toolbars?
     
     
     

    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

  •  04-10-2006, 9:20 PM 18085 in reply to 18068

    Re: Beyond MaxTextLength ... Real Time Text Characters Remaining Displayed ... Possible?

    Hi Adam,
     
    Thanks for getting back to me so promptly.
     
    The events are now firing. I used slightly different logic but it is none the less working. The MAIN PROBLEM NOW is that when I click on the HTML or Preview view, the event attachment is lost.
     
    Can you tell me if a NEW EDITOR is created each time you change view. Perhaps this is the problem. If so, I cannot see any way of amending this unless we can wire into that event somehow.
     
    If you would like a preview as to how I am using this, please go to:
     
        http://60.225.201.133/dkc/dkc.web.administration/clients.aspx - The editor at the top of page is the one I am testing with. This is a temporary address so please tell me if it goes stale.
     
    Thanks for your help Adam. 
    I still really love your editor! It is the best out there at the moment and has been for a while.
     
    P.S. If you have time to check it out, can you tell me why the 404 Page Not Found is coming up when the editor loads. To test, simply press the Load Button and look closely at the editor. 404 is displayed, THEN it loads the template.

    Stephen McCormack
    MWeb Solutions Pty Ltd
    http://www.mwebsolutions.com.au
  •  04-10-2006, 9:29 PM 18086 in reply to 18085

    Re: Beyond MaxTextLength ... Real Time Text Characters Remaining Displayed ... Possible?

    Stephen,
     
    Thanks for the nice comments about CuteEdiotr.
     
    I got a JavaScript error "permission denied" when the page loads.
     
    Can you remove all the other controls and create a simple test page?
     
    Which version of CuteEditor are you using?
     
     
     
     

    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

  •  04-10-2006, 9:45 PM 18088 in reply to 18086

    Re: Beyond MaxTextLength ... Real Time Text Characters Remaining Displayed ... Possible?

    Adam,

    I have placed a test page at:

        http://60.225.201.133/dkc/dkc.web.administration/test.aspx  

    If you need to access the global javascript file, go to :

        http://60.225.201.133/dkc/dkc.web.administration/includes/javascript/global.js 

    All the editor script is located at the bottom/end of the HTML source (as I have RegisteredStartupScript with ASP.NET).
     
    I really appreciate you looking at this for me as I am working it on aggressively now.
    I am making as ASP.NET Custom Control to include all these features - perhaps this could be a feature request for future versions. 
     
    NOTE: Can you check out the 404 error also.

    Thanks again.

     

     


    Stephen McCormack
    MWeb Solutions Pty Ltd
    http://www.mwebsolutions.com.au
View as RSS news feed in XML