Reputation: 5117
I try to use the same ckeditor replace several time in a ajax form:
... <textarea id="textareaId"></textarea> ...
And a javascript code
CKEDITOR.replace('textareaId');
$('#textareaId').val("first");
CKEDITOR.replace('textareaId');
$('#textareaId').val("second");
Can somepody know why id does not show "second" instead of "first" in the textarea with ckeditor? And how to get the correct value $('#textareaId').val()? Thank you
Upvotes: 0
Views: 75
Reputation: 1684
I think you should force destroying instance before replace again.
var editor = CKEDITOR.instances['textareaId'];
if (editor) {
editor.destroy(true);
}
CKEDITOR.replace('textareaId');
Upvotes: 1
Reputation: 24019
Id
s should be unique, so (I don't use CKEditor btw so no clue what this is trying to achieve but am explaining how ids should be used):
<textarea id="textareaId"></textarea>
<textarea id="textareaId2"></textarea> <!-- changed id -->
CKEDITOR.replace('textareaId');
$('#textareaId').val("first");
CKEDITOR.replace('textareaId2'); /* new id for text area */
$('#textareaId2').val("second");
Upvotes: 1