Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ckeditor textarea value using jquery?

I am using ckeditor on textarea but i could not get data from it.

Code :

<textarea name="DSC" class="materialize-textarea"></textarea>
<script>
  CKEDITOR.replace('DSC');
  </script>

Jquery :

var title = $('input[name=TITLE]').val();
    var desc = $('textarea[name=DSC]').text();
    var formdata = 'TITLE='+title+'&DSC='+desc;
like image 487
Manish Tiwari Avatar asked May 21 '16 10:05

Manish Tiwari


People also ask

How can I get multiple CKEditor values in jQuery?

each(function(index, element){ $(element). ckeditor(); }); should be enough since . ckeditor has access to the item's id. element.

How do I get CKEditor text?

Re: Get textvar editorData = CKEDITOR. instances. editor1. getData();

Does CKEditor use jQuery?

Thanks to these changes CKEditor 4 automatically works with the official jQuery Form Plugin for Ajax-based forms. It does not require any action from the developer's side to support it.

How do I save my CKEditor data?

Saving Data in CKEditor 4 Replacing a Textarea CKEditor 4 automatically updates the replaced <textarea> when the form is submitted, so there is no need to change any server-side code handling form submission after enabling CKEditor on an exisiting form element.


3 Answers

No need for jQuery CKEditor has its own method to get data from converted textarea:

var desc = CKEDITOR.instances['DSC'].getData();

OR:

var desc = CKEDITOR.instances.DSC.getData();
like image 130
Bogdan Kuštan Avatar answered Oct 28 '22 21:10

Bogdan Kuštan


Use id attibute in textarea and use that id in CKeditor instead of textarea's name check bellow

<textarea name="textareaname" id="textarea-id"></textarea>
CKEDITOR.replace( 'textarea-id');//use id not name//
var ckValue = CKEDITOR.instances["textarea-id"].getData(); or
var ckValue = CKEDITOR.instances.textarea-id.getData();
like image 44
Palash Avatar answered Oct 28 '22 23:10

Palash


alert(CKEDITOR.instances.DSC.getData());

like image 2
Muhammad Awais Avatar answered Oct 28 '22 23:10

Muhammad Awais