After several (and I mean several) attempts to get this working, I've failed.
I've tried the ajax method in the wiki, but all that does is replace my code below with the text editor. I need to be able to dynamically insert a textarea, with the text editor. What I have below is the closest I've come to what I need. However, when clicking the link to call the add() function, I'm presented with an alert telling me that it can't find the textarea art_text[1].
I've tried the ajax method in the wiki, but all that does is replace my code below with the text editor. I need to be able to dynamically insert a textarea, with the text editor. What I have below is the closest I've come to what I need. However, when clicking the link to call the add() function, I'm presented with an alert telling me that it can't find the textarea art_text[1].
<script type="text/javascript">
// <![CDATA[
var elCount = 1;
function add() {
var parent = document.getElementById('parent');
var div = document.getElementById('article');
/* creating new article div */
var article = document.createElement('DIV');
var inntertext = "";
/* setting new div id and name attributes */
article.id = 'article' + elCount;
article.name = 'article' + elCount;
/* FCKeditor */
article.textarea = 'art_txt['+ elCount +']';
var fck = new FCKeditor(article.textarea);
fck.BasePath = "<?php echo SITE_URL ?>/admin/includes/classes/fckeditor/";
fck.ReplaceTextarea();
/* preparing new article form */
inntertext += '<div class="outer">';
inntertext += 'Article Text:';
inntertext += '<textarea name="art_txt[' + elCount + ']"></textarea>';;
inntertext += '</div>';
/* setting innerHTML of new div */
article.innerHTML = inntertext;
/* appending the new div to parent */
parent.appendChild(article);
elCount++;
}
// ]]>
</script>
Re: integrating with ajax
Re: integrating with ajax
<script type="text/javascript"> // <![CDATA[ var elCount = 1; function add() { var parent = document.getElementById('parent'); var div = document.getElementById('article'); /* creating new article div */ var article = document.createElement('DIV'); var inntertext = ""; /* setting new div id and name attributes */ article.id = 'article' + elCount; article.name = 'article' + elCount; article.textarea = 'art_txt['+ elCount +']'; /* preparing new article form */ inntertext += '<div class="outer">'; inntertext += 'Article Text:'; inntertext += '<textarea name="art_txt[' + elCount + ']"></textarea>';; inntertext += '</div>'; /* setting innerHTML of new div */ article.innerHTML = inntertext; /* appending the new div to parent */ parent.appendChild(article); /* FCKeditor */ var fck = new FCKeditor(article.textarea); fck.BasePath = "<?php echo SITE_URL ?>/admin/includes/classes/fckeditor/"; fck.ReplaceTextarea(); elCount++; } // ]]> </script>You can only replace a textarea that already exists within the document. Once you create the new DIV, you set the innerHTML and append it to the parent object. That will actually create the div and the textarea in the document. Then replace the textarea with FCKeditor.
Re: integrating with ajax
Re: integrating with ajax
function FCKeditor_OnComplete( editorInstance ) { editorInstance.SetHTML(htmlPreload); }It takes some time to fully create the editor. The FCKeditor_OnComplete function is designed to run only when the editor is fully instantiated.