How to insert text dynamically in CKEDITOR
Asked Answered
S

3

8

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.

Sampling answered 30/7, 2015 at 8:14 Comment(0)
G
12

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);
}
Grissom answered 30/7, 2015 at 8:20 Comment(2)
how would i know to put that data i have 10 rows and have id's on each column..i want to put the answer on the second row only. You gave is refresh all in the text editor and paste the string.Sampling
Get the data, construct a jQuery object from it, change the values, and put the data back in.Embay
A
7

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. ;)

Alliber answered 24/3, 2017 at 23:45 Comment(0)
E
1
CKEDITOR.instance['editor1'].insertElement(str);

It will be insert text in cursor position

Erlandson answered 8/12, 2016 at 3:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.