javascripttinymcewysiwyg

How to populate tinymce with some content on trigger of javascript event?


i want to populate the tinymce body with some content on trigger of onchange event of selectbox in javascript. I tried some stuff but it did not work for me.Please guide me in right direction. Here is the my code that appends the tinymce on textarea

$(function() {
appendTinyMCE();
function appendTinyMCE(){
    tinyMCE.init({

        // General options
        mode : "textareas",
        theme : "advanced",
        plugins : "preview",
        // Theme options
        theme_advanced_buttons1 : "forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,|,formatselect,fontselect,fontsizeselect,sub,sup,|,bold,italic,underline,strikethrough",
        theme_advanced_buttons2 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true

});}

});

here is the html code

<td>
        <textarea rows="15" name="MyTinymceContent" cols="90" >MyTestContent</textarea>

Now i want to populate the tinymce with new content , on change of select box in javascript. So i write the below code snippet on change of select box

 function populateMyTinyMCE() {
  document.form.MyTinymceContent.value ="MyNewContent";
 }

But it does not put the new content in tinymce body. I am not sure what i am missing here?


Solution

  • You can call any of following on some event trigger:

    tinyMCE.get('your_editor').setContent("MyNewContent");
    //OR
    tinyMCE.activeEditor.setContent('MyNewContent');
    

    See: Here for More