• I’m creating a plugin that has multiple instances of tinymce in a form. I just want to update a textbox with the character count onkeyup.
    As it stands, I have a button that will update the count and it’s working with this code activated with an onclick event:

    function getStats(id,mytbid) {
        var body = tinymce.get(id).getBody(), text = tinymce.trim(body.innerText || body.textContent);
    	var amhtextbox = document.getElementById(mytbid);
    	var ed = tinyMCE.activeEditor;
    	amhtextbox.value=text.length;
    	ed.focus();
        return {
            chars: text.length,
            words: text.split(/[\w\u2019\'-]+/).length
        };
    }

    I also found this code for the keyup event. I tried putting it in my theme’s function file, but can’t get it to work.

    setup: function(ed) {
        ed.on('keyup', function(e) {
            console.log('Editor contents was modified. Contents: ' + ed.getContent());
            check_submit();
        });
    }

    Any help/suggestions/tips would be appreciated!

  • The topic ‘Char Count with Tinymce’ is closed to new replies.