Adding a stripHTML function and counting characters

Last post 11-10-2005, 7:36 PM by m245. 6 replies.
Sort Posts: Previous Next
  •  08-26-2005, 5:50 PM 9953

    Adding a stripHTML function and counting characters

    I have a need to be able to count the non-HTML characters in the CE fields. For this reason, I've been trying to modify the include to add a javascript function to the textarea. However, no matter what I place in the onBlur, it won't execute (even a simple alert). All my logic works correctly in the non-RTE textarea (I started there and got it perfected). But when I transition to adding it to the RTE, I get nothing onBlur.

    Does CE somehow block onBlur?

    Here is my relevant code. First chunk is my external JS function, second chunk is a snippet of include_CuteEditor.asp. I added a property s_maxRTElength by duplicating the format of s_maxhtmllength.

    <SCRIPT LANGUAGE="JavaScript">
    function checkLength(toCheck, maxLength) {
        var stripped = toCheck.replace(/(<([^>]+)>)/ig,"");
        var diff = stripped.length - maxLength;
        if (diff > 0) {
            alert('The maximum length for this statement is ' + maxLength + ' characters (roughly 5 pages). Your entry exceeds that length by ' + diff + '.');
            this.focus();
        }
    }
    </SCRIPT>


    Response.Write "<TEXTAREA name="""&ID&""" rows="""&s_textareaRows&""" cols="""&s_textareaCols&""" style=""DISPLAY: none; WIDTH: " & s_width & "; HEIGHT: " & s_height & """ ID="""&ID&""" onBlur=""checkLength(this.value, " & s_maxRTElength & ");"">" & Server.HTMLEncode( s_Text ) & "</TEXTAREA>"


    Any help would be appreciated. It's important for us to be able to count the non-html characters. If there's an easier way to do this, by all means, let me know!

    Thanks,
    Jess
  •  08-29-2005, 1:16 PM 9997 in reply to 9953

    Re: Adding a stripHTML function and counting characters

    Jess, 

    Please put your code into the Iframe instead of textarea.
     
    <iframe onKeyDown="checkIt"></iframe>
    <script language="JavaScript">
    function checkIt()
    {
        var stripped = obj_Editor1.editdoc.body.innerText;
       var diff = stripped.length - maxLength;
        if (diff > 0) {
            alert('The maximum length for this statement is ' + maxLength + ' characters (roughly 5 pages). Your entry exceeds that length by ' + diff + '.');
            this.focus();
        }
    }
    </script>

    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

  •  08-29-2005, 5:49 PM 10002 in reply to 9997

    Re: Adding a stripHTML function and counting characters

    Hmmm, well thanks for the tip. I wondered if Iframe might be worth a shot. Unfortunately, it didn't work. Here's my latest code (ASP followed by updated Javascript, changes highlighted in red):

    ----------------------------------------------------------
                Response.Write("<iframe id="""&obj_ID&"_editBox"" src="""&GetURL("template.asp")&""" FrameBorder=""0"" class=""CuteEditorFrame"" style=""border-color:#C0C0C0;border-width:1px;border-style:Solid;height:100%;width:100%;"" onKeyDown=""checkLength();""></iframe>")
                Response.Write("<TEXTAREA name="""&ID&""" rows="""&s_textareaRows&""" cols="""&s_textareaCols&""" style=""DISPLAY: none; WIDTH: 100%; HEIGHT: 100%; valign: top"" ID="""&ID&""">" & Server.HTMLEncode( s_Text ) & "</TEXTAREA>")

    ---------------------------------------------

    <SCRIPT LANGUAGE="JavaScript">
    function checkLength() {
        var maxLength = 20;
        var stripped = document.getElementById('Resume1').innerText;
        var diff = stripped.length - maxLength;
        if (diff > 0) {
            alert('The maximum length for this statement is ' + maxLength + ' characters (roughly 5 pages). Your entry exceeds that length by ' + diff + '.');
            this.focus();
        }
    }
    </SCRIPT>
    ---------------------------------------------

    For good measure, I tried the var = stripped line exactly as you provided. That also did not work. I also tried hard-coding the maxlength for now, just until I can get it working.

    The issue is that the checkLength function is never getting called. I've put alerts all over the place for testing (excluded here) and I can say with confidence that I'm never getting inside the checkLength function, whether it's called from the textarea in an onblur, from the form in an onsubmit or onunload, or from the iframe in an onkeydown.

    Any other ideas?

    Thanks,
    Jess
  •  09-06-2005, 5:13 PM 10181 in reply to 10002

    Re: Adding a stripHTML function and counting characters

    Hello? Patiently waiting for a response and possible other fixes... tried what was suggested and it didn't work. See my previous post for the details, and let me know if you need more specifics.

    Thanks,
    Jess
  •  09-06-2005, 5:25 PM 10182 in reply to 10181

    Re: Adding a stripHTML function and counting characters

    Jess,
     
    Please wait a sec.
     
    I'll write an example for you.
     
     

    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-06-2005, 5:37 PM 10183 in reply to 10182

    Re: Adding a stripHTML function and counting characters

  •  11-10-2005, 7:36 PM 12497 in reply to 10183

    Re: Adding a stripHTML function and counting characters

    Adam,
     
    Can you provide a sample code for the OnBlur event instead of the onKeyPress?.  I have similar problem geting the OnBlur to work, and the onKeyPress is not an acceptable solution.  Thanks in advance.
View as RSS news feed in XML