Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert text dynamically in CKEDITOR

I use plugin CKEDITOR for word editor in my web. Inside the editor I have a table which have two columns . I want to achieve that in the first column if the user input number it will add to (50) and the result automatically appear in the second column. That is very easy using Jquery but it does not work. Tried codes:

function insertIntoCkeditor(str){
  CKEDITOR.instances['editor1'].insertText(str);
}

but this code insert automatically above the text area of the editor.

like image 446
Goper Leo Zosa Avatar asked Jul 30 '15 08:07

Goper Leo Zosa


3 Answers

Use

setData()

It will remove the existing data in the ckeditor and and it will replace it with 'str' variable content.

function insertIntoCkeditor(str){
    CKEDITOR.instances['editor1'].setData(str);
}
like image 124
Arun Kumar Avatar answered Sep 23 '22 05:09

Arun Kumar


I am using insertHtml : It will put the text at cursor position and no removal of existing text. Its like updating the content of ckeditor. this separates it from setdata()

function InsertHTML(HTML)
{
  CKEDITOR.instances['editor1'].insertHtml(HTML);
}

and it works fine. ;)

like image 29
BlueMan Avatar answered Sep 21 '22 05:09

BlueMan


CKEDITOR.instance['editor1'].insertElement(str);

It will be insert text in cursor position

like image 44
Mari Selvan Avatar answered Sep 19 '22 05:09

Mari Selvan