Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set a value in CKEditor with Javascript?

I am wondering how I can set a value in CKEditor using Javascript?

I have tried the following, but neither of them work...

document.[form name].[textarea name].value=data; $('#textareaID').val(data); 

However, both these work without the editor applied. Is there a way I can do this with the editor?

like image 634
dcp3450 Avatar asked Aug 31 '10 14:08

dcp3450


People also ask

How does CKEditor set value?

[form name]. [textarea name]. value=data; $('#textareaID'). val(data);

How do I get CKEditor value?

try: var bodyAdd = CKEDITOR. instances['editor1']. getData();

What is JavaScript CKEditor?

CKEditor is a modern, feature-rich JavaScript text editor with clean UI and perfect UX. Easily customizable to any use case.

How does CKEditor display data?

You can display data in ckeditor by passing the variable value which you get from the database.


2 Answers

Use the CKEditor method setData():

CKEDITOR.instances[**fieldname**].setData(**your data**) 
like image 178
efeyc Avatar answered Sep 19 '22 03:09

efeyc


The insertHtml() and insertText() methods will insert data into the editor window, adding to whatever is there already.

However, to replace the entire editor content, use setData().

like image 26
Wick Avatar answered Sep 21 '22 03:09

Wick