Question

I read this post on this and am trying to simply add text via jQuery into my CKEditor. I am using this code but it gives the following error:

$(document).ready(function(){
    CKEDITOR.instances.txtDESCRIPTION.insertText('some text here');
});

---

<%@ Register TagPrefix="CKEditor" Namespace="CKEditor.NET" Assembly="CKEditor.NET" %>
<CKEditor:CKEditorControl id="txtDESCRIPTION" Toolbar="SplendidCRM" Language='<%# Session["USER_SETTINGS/CULTURE"] %>'  Height="400" BasePath="~/ckeditor/" FilebrowserUploadUrl="../ckeditor/upload.aspx" FilebrowserBrowseUrl="../Images/Popup.aspx" FilebrowserWindowWidth="640" FilebrowserWindowHeight="480" runat="server" />

Uncaught TypeError: Cannot call method 'insertText' of undefined

How can I simply add the text "test" to my CKEditor?

Note: This uses CKEditor.NET, not the jQuery CKEditor version.

Was it helpful?

Solution 2

This is result of a bug in CKEditor as documented here http://dev.ckeditor.com/ticket/6497. As a workaround, I simply append text on button click like so:

$('#myBtn').click(function(){
    CKEDITOR.instances._ctl0_cntBody_ctlEditView_txtDESCRIPTION.insertText('some text here');
});

OTHER TIPS

Have you called CKEDITOR.replace('txtDESCRIPTION') yet?

if so then oEditor.setData('test') should do the trick.

Edit:

it appears that ckeditor.net is renaming the id

from the link in the comment bellow

You can get around the problem of controls being renamed by finding the ClientID of the control. I put code in the codebehind to find the control's ID and set Javascript for it. That way the code is not affected by rearranging controls on the form. If there is more than one editor instance on a form, simply call InsertEditorJS for each one.

Here is the codebehind:

protected void Page_Load(object sender, EventArgs e)
{
    TextBox qiiEditor = (TextBox) FormView1.FindControl("qiiTextBox");
    Literal qiiJS = (Literal) FormView1.FindControl("qiiTextBoxJavascript");
    InsertEditorJS(qiiEditor, qiiJS);
}
protected void InsertEditorJS(TextBox TextBoxCtl, Literal LiteralCtl)
{
    LiteralCtl.Text = "<script type='Text/javascript'>";
    LiteralCtl.Text += "CKEDITOR.replace('";
    LiteralCtl.Text += TextBoxCtl.ClientID;
    LiteralCtl.Text += "');</script>";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top