Using jQuery to set CKEditor value

I have a CKEditor text box:

<textarea cols="80" id="taBody" name="taBody" class="ckeditor" rows="10" runat="server"></textarea> 

I have jQuery trying to set a value from a database:

 $('#ContentPlaceHolder_taBody').val(substr[5]); 

Don’t worry about the substring in which I already tested that it returns a string. For testing purposes, I replaced the substring "test" and got the same problem.

I know that the jquery surrounding this line does not affect it, because the other text fields I'm trying to fill work. Just when it comes to ckeditor.

Here is the script as a whole:

 function (obj) { $.ajax({ type: "POST", url: "ContentSections.aspx/GetContentDetails", data: '{"nodeID": "' + obj.attr('id') + '"}', contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { var str = msg.d; var substr = str.split('|||'); $('#ContentPlaceHolder_hfContentSectionID').val(substr[0]); $('.txtAlias').val(substr[1]); $('.txtBrowserTitle').val(substr[2]); $('.txtMetaDescription').val(substr[3]); $('.txtMetaKeywords').val(substr[4]); $('#ContentPlaceHolder_taBody').val(substr[5]); } }); } 

The problem was that nothing was populated and no javascript errors were shown.

I tried to read, but could not find anything that helped me. Does anyone have any idea?

+7
source share
2 answers

Instead, you need to use the CKEditor API.

In particular, http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData

+25
source

After reading this link http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData , the following code works for me.

 CKEDITOR.instances.editor1.setData( '<p>This is the editor data.</p>' ); 
+1
source

All Articles