Sanfly Sanfly - 1 year ago 183
Javascript Question

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:

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

Answer Source

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

// 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()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download