Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every body,

I am using Ajax control Html editor for geting and showing data. I am using charecter counters and also validate on client-side. It works fine in IE but not in FF and chrome. In FF and chrome it don't count and don't change validate color (wrong), but in IE it do (correct). Can any one help me??? Code is given below;
XML
<custom:HtmlEditor ID="txtJobDetails"  runat="server" Height="150px" TabIndex="4" />
                            <asp:HiddenField ID="hfOldContants" runat="server" />
 <asp:Label ID="lblJobDetails" runat="server" Text="3000"></asp:Label>

and in javascript;
JavaScript
Sys.Application.add_load(function () {
            var editor = $find("<%= txtJobDetails.ClientID %>");  // Editor's ID="myEditor" 

            var editPanel = editor.get_editPanel();
            var designPanel = editPanel.get_modePanels()[AjaxControlToolkit.HTMLEditor.ActiveModeType.Design];

            editPanel._setActive_saved = editPanel._setActive;

            editPanel._setActive = function () {
                if (this.get_activeMode() == AjaxControlToolkit.HTMLEditor.ActiveModeType.Design) {
                    var designPanel = this.get_activePanel();
                    designPanel.onContentChanged();
                }
                this._setActive_saved();
            };

            

            designPanel.onContentChanged = function () {
                var innerText;
                var hfOldContants = document.getElementById("<%=hfOldContants.ClientID %>");
                if (AjaxControlToolkit.HTMLEditor.isIE) {
                    innerText = this._doc.body.innerText;
                } else {
                    var div1 = document.createElement("div");
                    var html = new AjaxControlToolkit.HTMLEditor.jsDocument(true);
                    AjaxControlToolkit.HTMLEditor.__MozillaGetInnerText(div1, html);
                    innerText = html.toString();
                    delete div1;
                    delete html;
                }

                // HTML text length 
                var htmlTextLength = AjaxControlToolkit.HTMLEditor.Trim(this._doc.body.innerHTML).length;
                var txt = innerText;
                // Plain text length 
                var plainTextLength = innerText.replace(/^[\s]+/g, "").replace(/[\s]+$/g, "").replace(/[\s]+/g, " ").length;

                // Place here your code: 

                if (txt.length > 3000) {
                    $find("<%= txtJobDetails.ClientID %>").set_content(hfOldContants.value);
//                    $(this._doc.body).css('backgroundColor', '#FFFFD4');
                    alert("Exceeded Character Limit");
                    return false;
                }
                else {
                    document.getElementById("totalHtml").value = htmlTextLength + " Chars Used";
                    $("#<%=lblJobDetails.ClientID %>").html(3000 - (txt.length) + " chars left");

                    hfOldContants.value = AjaxControlToolkit.HTMLEditor.Trim(this._doc.body.innerHTML);
                    hfOldContants.innerHTML = AjaxControlToolkit.HTMLEditor.Trim(this._doc.body.innerHTML);

                    if ($("#<%=lblJobDetails.ClientID %>").html() == "3000 chars left") {
                        $(this._doc.body).css('backgroundColor', '');
                        $(this._doc.body).css('backgroundColor', '#FFFFD4');
                    }
                    else {
                        $(this._doc.body).css('backgroundColor', '');
                    }

                }
            }
});

Regards,
Atiq
Posted
Updated 26-Jan-12 3:44am
v2

1 solution

 
Share this answer
 
v2
Comments
Atiq Rehman 28-Jun-12 9:42am    
This is not the solution boss :)
Vipin_Arora 30-Jun-12 2:36am    
Hi atiq,
I have improved my answer, these links might help you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900