Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using JQuery to set CKEditor Value

I have a CKEditor textarea:

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

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

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

Don't worry about the substring I already tested that it is returning a string. For testing purposes I replaced the substring with 'test' and was receiving the same issue.

I know that the jquery surrounding this line doesn't affect it because the other textfields I'm trying to populate work. Just when it comes to the ckeditor.

Here is the script in 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 issue was that nothing was being populated and no javascript errors were being shown.

I tried to read around but couldn't find anything that helped me. Does anyone have any ideas?

like image 273
balexander Avatar asked Apr 01 '11 22:04

balexander


People also ask

How to use CKEditor in jQuery?

Creating Editor InstancesThe ckeditor() method is the main method of the jQuery Adapter. It accepts two optional parameters: A callback function to be executed when the editor is ready. Configuration options specific to the created editor instance.

Does Ckeditor need jQuery?

Of course, possible use CKEditor without jQuery. jQuery adapter used only for treat CKEditor as jQuery object via $. All basic CKEditor plugins(components) not used jQuery too. However, a few extented CKEditor plugin as "Accessibility Checker" demand of jQuery.

How do you call Ckeditor in HTML?

To start, create a simple HTML page with a <textarea> element in it. You will then need to do two things: Include the <script> element loading CKEditor 4 in your page. Use the CKEDITOR.


2 Answers

You need to use CKEditor's API instead.

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

like image 148
simshaun Avatar answered Oct 18 '22 22:10

simshaun


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

CKEDITOR.instances.editor1.setData( '<p>This is the editor data.</p>' );
like image 22
Ravi Mane Avatar answered Oct 18 '22 22:10

Ravi Mane