AttachEvent + Multiple Editors

Last post 02-09-2006, 10:16 AM by sbarrier. 0 replies.
Sort Posts: Previous Next
  •  02-09-2006, 10:16 AM 15768

    AttachEvent + Multiple Editors

    I'm using the sample Javascript API code that you provided to generate a "Characters Left" counter for an aspx page that has 2 Editors. The first Editor works great. I can't get the 2nd Editor to work at all. Although it appears that the attachEvent code for the 2nd one is working correctly, it never fires on the onkeyup event.
     
    Here is my javascript code:
     

    function initEditorCount() {
    //Editor 1 - Short Description
    var editor1 = document.getElementById("<% =Editor1.ClientID %>");
    var editdoc=editor1.GetDocument();
    editdoc.attachEvent("onkeyup", function() { WordCount("<% =Editor1.ClientID %>", "<% =Editor1Length.ClientID %>", 275); });

    //Editor 2 - Description
    var editor2 = document.getElementById("<% =Editor2.ClientID %>");
    var editdoc2=editor2.GetDocument();
    editdoc2.attachEvent("onkeyup", function() { WordCount("<% =Editor2.ClientID %>", "<% =Editor2Length.ClientID %>", 8000); });
    }

    function WordCount(obj, obj2, iMaxLen) {
    alert("Word Count");
    var editor1 = document.getElementById(obj);
    var editdoc=editor1.GetDocument();
    var sVal = editdoc.body.innerHTML;
    var iLen = iMaxLen - sVal.length;
    document.getElementById(obj2).innerHTML = iLen;
    if (iLen<100) {
    document.getElementById(obj2).style.color="red";
    }
    else {
    document.getElementById(obj2).style.color="rosybrown";
    }

    }
     
    The alert in WordCount() will fire upon every keystroke for the 1st editor, but will never fire for the 2nd editor. Any ideas?
View as RSS news feed in XML