1

I am getting this error : Uncaught TypeError: Cannot read property 'getContent' of undefined

if (tinymce.editors.length > 0) {
                alert('editor exist')
                var myEditor = tinyMCE.get['rteCaseHeading'].getContent();
                $("#bookId").html(myEditor);
            }

In Html :

<textarea class="mceEditor" id="rteCaseHeading"  rows="10" cols="100" style="height: 300px"> </textarea>

I also have specified : editor_selector : "mceEditor",during tinyMCE init.

I have referred various links/questions on this error and implemented.

This somehow still throws error though length of editors is greater than zero.

Someone , please suggest am struggling since more than 2-3 hrs with this issue. [UPDATE]

I referred this link and added the below code : http://jsfiddle.net/9euk9/49/

 ed.on('change', function () {
                    ed.save();
                });

Still, no luck. Thanks a lot!

3
  • Are you calling the .triggerSave(); method before using the .getContent(); method? Commented Sep 12, 2016 at 12:20
  • Hello , I am not calling any other method. Could you please guide me here? I am using version 3.X . Thank You ! Commented Sep 12, 2016 at 12:26
  • Hi David R, I read your comment and added ed.save(); as well. Still no luck, Please suggest ! Commented Sep 12, 2016 at 12:37

2 Answers 2

1

Enclose your <textarea> inside <form></form> tags.

Checkout the below code,

HTML

<form method="post" action="action_page">
<textarea class="mceEditor" id="rteCaseHeading"  rows="10" cols="100" style="height: 300px">testtestet</textarea>
</form>

<button onclick="content()">Get content</button>

Javascript

tinyMCE.init({
        mode : "specific_textareas",
        editor_selector : "mceEditor"  
});

function content(){
    alert(tinyMCE.get('rteCaseHeading').getContent());
}

Working Fiddle - http://jsfiddle.net/kqa13zz4/52/

Note: In fiddle, I have written the function content() function as window.content = function()... since fiddle accepts function declaration in that way only.

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

0

You are not calling the get() method correctly. You have this:

var myEditor = tinyMCE.get['rteCaseHeading'].getContent();

...it should be this:

var myEditor = tinyMCE.get('rteCaseHeading').getContent();

The way you have things written you are trying to access an array on the tinyMCE object - but the get is a method not an array - it is a method on the tinyMCE object hence the need for parenthesis and not square brackets.

https://www.tinymce.com/docs/api/tinymce/root_tinymce/#get

(the method call is the same for TinyMCE 3 and 4)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.