Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Value Inside a TinyMCE Editor using jQuery

Tags:

Hi I need to set predefined content inside the tinyMCE Editor. Below is my html and jquery.

<script type="text/javascript">     tinyMCE.init( {         mode : "exact" ,         elements : "country"     }); </script> <script type="text/javascript">     $(function() {         $("#lang").change(function() {             var s = $(this).val(); alert(s);             $("#country").val(s);         })     }) </script>   <select id="lang">         <option value="">Please Select country</option>         <option value="us">US</option>         <option value="es">SPAIN</option>         <option value="jp">JAPAN</option>     </select><br /><br />     <textarea id="country" cols="10" rows="5"></textarea> 

The script works for a normal textarea but not for tinyMCE. Is there anything I am doing wrong in this.

Thanks

like image 538
Mike Avatar asked Dec 20 '11 13:12

Mike


People also ask

How do you value TinyMCE?

getContent() method. to add the TinyMCE script and text area, then we can get the value when the editor is initialized by writing: tinymce. init({ selector: '#mytextarea', setup(editor) { editor.

Does TinyMCE need jQuery?

You don't need to use tinymce as a jQuery plugin but the option is there if you would like to. The vast majority of the tinymce source code is in the tinymce. min. js file and the jQuery.


1 Answers

I think you can do:

$(function() {     $("#lang").change(function() {         var s = $(this).val();          alert(s);         tinyMCE.activeEditor.setContent(s);     }); }); 
like image 53
karim79 Avatar answered Dec 08 '22 12:12

karim79