Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
102
rated 0 times [  109] [ 7]  / answers: 1 / hits: 31652  / 10 Years ago, tue, january 6, 2015, 12:00:00

  1. I have a data from database.

  2. In my js file, I would like to change my CKEditor text editor's value.

  3. My value is raw html.

  4. I want this raw value to be written on an empty CKEditor text editor.



I tried these but got an undefined function error all the time :



CKEDITOR.instances.myEditorID.insertHtml( '<p>This is a new paragraph.</p>' );
CKEDITOR.instances.myEditorID.setData( '<p>This is the editor data.</p>' );


I tried this too but still undefined function error :



CKEDITOR.instances.YOUREDITORID.updateElement();
alert( document.getElementById( 'YOUREDITORID' ).value );


Instead of myEditorID i tried 'editor', 'editor1', 'editor2' but still doesn't work for me.



Thanks in advance.



---Update---



This is the html of my ckeditor text editor :



<textarea id=myEditorID name=myEditor></textarea>
<script type=text/javascript>
$(function () {
var myEditor = $('#myEditorID');
myEditor.ckeditor({
height: 200,
extraPlugins: 'charcount',
maxLength: 2000,
toolbar: 'TinyBare',
toolbar_TinyBare: [
['Bold','Italic','Underline'],
['Undo','Redo'],['Cut','Copy','Paste'],
['NumberedList','BulletedList','Table'],['CharCount']
]
}).ckeditor().editor.on('key', function(obj) {
if (obj.data.keyCode === 8 || obj.data.keyCode === 46) {
return true;
}
if (myEditor.ckeditor().editor.document.getBody().getText().length >= 2000) {
alert('You have reached the maximum char length');
return false;
}
});
});
</script>

More From » html

 Answers
19

Instead of myEditorID i tried 'editor', 'editor1', 'editor2' but still
doesn't work for me.




You need to look at the HTML of your page and see what the ID field is for your editor. It will be something like this



<textarea id=my_editor></textarea>


That id attribute is what needs to go in here



CKEDITOR.instances.my_editor.insertHtml('<p>This is a new paragraph.</p>');

[#68298] Friday, January 2, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janjadonb

Total Points: 4
Total Questions: 114
Total Answers: 118

Location: Mali
Member since Fri, Dec 3, 2021
3 Years ago
janjadonb questions
;