harry_beginner
harry_beginner

Reputation: 64

Replace Tinymce textarea contents on page load

Thanks for message. Actually, I trying to write a mail program. In that, I have a textarea field and a dropdown menu consisting of 4 templates. I have replace the textarea contents depending on dropdown selection.

 $(document).ready(function () {
  $('div#template textarea.mceEditor').html($('div div#template1').text()); 
    $('textarea.mceEditor').attr('readonly','readonly');    
    $('#selecttemplate').change(function () {   

       if($(this).val() == 'template1'){ 
          $('div#template textarea.mceEditor').html($('div div#template1').text());                               $('textarea.mceEditor').attr('readonly','readonly');        

       }
       else if($(this).val() == 'template2'){ 
          $('div#template textarea.mceEditor').html($('div div#template2').text());
          $('textarea.mceEditor').attr('readonly','readonly');

       }
       else if($(this).val() == 'template3'){
          $('div#template textarea.mceEditor').html($('div div#template3').text());
          $('textarea.mceEditor').attr('readonly','readonly');

       }
       else if($(this).val() == 'template4'){
          $('div#template textarea.mceEditor').html($('div div#template4').text());

          $("textarea.mceEditor").removeAttr('readonly');             
       }
    });

I can accomplish this template change in normal textarea. When I use this tinymce integration, it doesn't change the contents in the textarea. But it loads the first dropdown contents on page load.

Four different (sample)contents in order display in textarea based on drop down selection:

<div style="display:none;">
 <div id="template1" class="msg">
<?php echo $clickTracker->getAffiliate()->getValue('data1'); ?>
  123
<?php echo $clickTracker->getAffiliate()->getValue('data14'); ?>
</div>
<div id="template2" class="msg">
<?php echo $clickTracker->getAffiliate()->getValue('data1'); ?>
 456
 <?php echo $clickTracker->getAffiliate()->getValue('data10'); ?>
 </div>
 <div id="template3" class="msg">  
 <?php echo $clickTracker->getAffiliate()->getValue('data1'); ?>
 789
 <?php echo $clickTracker->getAffiliate()->getValue('data11'); ?>
 </div>
 <div id="template4" class="msg">
 Type your own message...
 </div>
 </div>

Thanks in Advance.

Upvotes: 0

Views: 1792

Answers (1)

naota
naota

Reputation: 4718

I guess you might want to use .setContent() like this:

 if($(this).val() == 'template1'){ 
       tinyMCE.activeEditor.setContent($('div div#template1').text());
 }

The document is here :http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.setContent

Upvotes: 1

Related Questions