Brandrally
Brandrally

Reputation: 849

Setting TinyMce on Ajax / Javascript textarea field

I have a form with a little bit Ajax / Javascript that adds / edits / removes.

One of the functions of the JS looks like:

$(".edit_row input:radio[type=radio]").live("click",function() {
var val=$(this).val();

var parent=$(this).parents("li").attr("id");

var text=jQuery("#"+parent).find("[name=text]").val();

switch(val){
case "1":   
var v='<input type="text" class="txtsmall" name="text" value="'+text+'" >';
jQuery("#"+parent).find(".resize").html(v);
break;
case "2":
var v='<input type="text" name="text" class="txtbig" value="'+text+'" >';
jQuery("#"+parent).find(".resize").html(v);
break;
case "3":
var v='<textarea name="text" class=" tinymce" rows="10">'+text+'</textarea>';
jQuery("#"+parent).find(".resize").html(v);
break;

}
});

One thing I would like to do is change the 'case 3' from a plain to become a tinymce (WYSIWYG).

Normally on the page head we would initiate tinymce:

$().ready(function() {
$('textarea.tinymce').tinymce({
script_url : '/javascript/wysiwyg/tiny_mce.js',
theme : "advanced"
});
});

Then class the textarea class="tinymce" and TinyMce does it's thing.

When I set the class within the javascript – It just doesn't display / call-in.

Can someone help me with the logic to call in to behave as a WYSIWYG field?

Still finding my way through js – any thoughts would be greatly appreciated!

Upvotes: 1

Views: 321

Answers (1)

Thariama
Thariama

Reputation: 50832

You may give your textarea an id and use this call to initalize your editor:

tinymce.execCommand('mceAddControl',true,'your_editor_id');

Upvotes: 1

Related Questions