Getting the value from a TinyMCE textarea

I have a news editor for my site with which I am using TinyMCE. What I would like to be able to do is have a button (outside of the TinyMCE editor itself) that I can click to scan the textarea for any images, then list those images as options to use for a thumbnail image for said news article.

For an idea of what I mean, please see this link here: https://docs.google.com/leaf?id=0B05m73kzudwPNzUwZjkyNmItYjZkMy00NTdlLTlkNDctOGRhYThjMzNjNTM5&hl=en_US

My problem is that document.getElementById('NewsArticle').value is not returning anything when there is text in the textarea

The other potential problem is that whats shown in the textarea is not actual code, but images etc too so I wasn't sure it would even work in the first place, but since when the form is submitted the data[News][article] value is back into text, I thought there might be a chance.

If anyone knows how to get either the content or code for the tinyMCE textarea, or has a better solution, I'd be interested to hear


Solution 1:

TinyMce has an api for accessing content from the editor.

This code will grab the html from the active editor:

// Get the HTML contents of the currently active editor
tinyMCE.activeEditor.getContent();

// Get the raw contents of the currently active editor
tinyMCE.activeEditor.getContent({format : 'raw'});

// Get content of a specific editor:
tinyMCE.get('content id').getContent()

Solution 2:

Use below syntax, which will remove unwanted character from your input textarea....

(((tinyMCE.get('YourTextAreaId').getContent()).replace(/(&nbsp;)*/g, "")).replace(/(<p>)*/g, "")).replace(/<(\/)?p[^>]*>/g, "");

Solution 3:

Try

window.parent.tinymce.get('contentID').getContent();

For some reason, the stock-standard tinymce.get() call didn't work for me, so I tried this and it works. :)

Solution 4:

var temp = tinymce.get('textAreaName').save();
console.log(temp);

OR

var temp =tinymce.get('textAreaName').getContent();
console.log(temp);