Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting value of textarea which is under control of tinymce editor using jquery without sending form

I have some textarea

<textarea name='text' id='text' ></textarea>

which is under control of tinymce script.

And I have simple javascript

alert ($('#text').val());

which gives me nothing. Problem is that tinymce is converting textarea into something , so actually there is no textarea with id 'text' anymore. Because of that javascript gives empty alerts when I press submit button even if there is some text typed in textarea.

So question is how can javascript get the value of such textarea on the fly whenever I need it ?

like image 669
David Avatar asked Jul 26 '11 13:07

David


2 Answers

It should be possible using the get [docs] and getContent [docs] methods:

var value = tinymce.get('text').getContent();
like image 165
Felix Kling Avatar answered Sep 28 '22 11:09

Felix Kling


There is a method of the TinyMCE instance that can "sync" the TinyMCE content (an IFRAME) with your textarea. I think the method is triggerSave(). Look also here: Need to autosave TinyMCE

like image 39
Claudio Avatar answered Sep 28 '22 11:09

Claudio