0

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.

harry_beginner
  • 64
  • 1
  • 1
  • 11
  • Plase clarify what you want to accomplish. Do you still want to be that textarea a TinyMCE-textarea (and maybe just show some first text in there) or do you want something completely different done with it? – Bjoern Jun 15 '14 at 18:16
  • Look at new requirement list above... – harry_beginner Jun 16 '14 at 08:12

1 Answers1

1

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

naota
  • 4,695
  • 1
  • 18
  • 21
  • Thanks for the code. It works. Could you please tell me how to disable/enable editing. – harry_beginner Jun 16 '14 at 08:51
  • @harry_beginner Thanks. You could go like this `tinyMCE.get('textarea_id').getBody().setAttribute('contenteditable', false);` You might want to check this question http://stackoverflow.com/questions/13881812/make-readonly-disable-tinymce-textarea – naota Jun 16 '14 at 08:55
  • Thanks so much. You've saved a lot of time. One more help please, how could I send images with mail. Now, It is not displaying images in email. – harry_beginner Jun 16 '14 at 09:17
  • @harry_beginner, thanks. Could you explain more about how you try to send image by mail? Do you use PHP or some script language on the server side? – naota Jun 16 '14 at 09:22
  • Now, I am implementing a simple mail program. But I have to send html email with some sort of templates contains images and links. At this moment, I have used php mail function in order to send mails. – harry_beginner Jun 16 '14 at 09:27
  • setAttribute is not working in document ready function. But it works when I change dropdown. Same with template change, setcontent is not working on page load, but my old code is doing fine. Anyway, I've sorted that problem. Thanks again @naota – harry_beginner Jun 16 '14 at 09:31
  • @harry_beginner thanks. I hope you accept my answer if it's good enough. And I guess you might want to post a new question about sending an image with mail. When you post a new quesion, I would be happy if you let me know. – naota Jun 16 '14 at 09:35