Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get tinyMCE content from more than one text area

Tags:

jquery

tinymce

Hi I have problem when I need to get the content from multiple text areas. So i saw that tinyMCE has methods to take content from specific text area or from active one, but how to do it will all text areas that i have ( note : Text areas count is not static ).

I was thinking for variant to create dynamic ID of each text area and when i need to submit the content to iterate thru all of them. Something like that:

for 0 to my textareas length
var all content = tinyMCE.get('area1').getContent();
var all content += tinyMCE.get('area2').getContent();

Something like that but i don't know if this is the right way. Please help me to solve that issue. Thanks in advance

like image 985
cyrat Avatar asked Apr 15 '13 13:04

cyrat


2 Answers

Tinymce stores all its editors in an array: tinyMCE.editors. All you need to do is to loop through them and access the content:

for (i=0; i < tinyMCE.editors.length; i++){
    var content = tinyMCE.editors[i].getContent();
    alert('Editor-Id(' + tinyMCE.editors[i].id + '):' + content);
}
like image 163
Thariama Avatar answered Sep 23 '22 15:09

Thariama


To reach multiple tinymce instances:

http://www.tinymce.com/wiki.php/API3:property.tinymce.editors

Example:

for (edId in tinyMCE.editors)
    tinyMCE.editors[edId].save();

and the best way (my opinion) would be to save the content to an array:

for (edId in tinyMCE.editors)
    array[edId] = tinyMCE.editors[edId].getContent();
like image 32
SG 86 Avatar answered Sep 23 '22 15:09

SG 86