Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 635
Sanfly Avatar asked Jun 30 '11 22:06

Sanfly


People also ask

How do I get content from TinyMCE textarea?

The TinyMCE getContent and setContent methods You can do this using the getContent() API method. Let's say you have initialized the editor on a textarea with id=”myTextarea”. This will return the content in the editor marked up as HTML.

How do I get TinyMCE editor value in jQuery?

function showPreview(value) { $("#preview-container"). load("/material-preview. php", {s:value}); } $('thetextarea'). live("keyup",function (e) { var material = this.


1 Answers

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() 
like image 168
Matthew Manela Avatar answered Oct 21 '22 11:10

Matthew Manela