I want to put the editor NicEditor when loaded with ajax. But the code below does not work. I use the Chrome browser and when the check element, error message is “uncaught TypeError: Can not call method ‘appendChild’ of null”.
This code runs for the div element “myNicPanel”. But do not run to “myNicPanel2”.
What should I do?
This is the main page (index.php):
[CODE]
<script type=”text/javascript” src=”ajax.js”></script>
<script type=”text/javascript” src=”http://js.nicedit.com/nicEdit-latest.js”></script>
<script type=”text/javascript”>
//<![CDATA[
bkLib.onDomLoaded(function() {
var myNicEditor = new nicEditor();
myNicEditor.setPanel(‘myNicPanel’);
myNicEditor.addInstance(‘myInstance1’);
});
function editProcess(sourcefile , div_to_replace)
{
var url= sourcefile;
ambilData(url,div_to_replace);
loadNicEditMe();
function loadNicEditMe()
{
var myNicEditor2 = new nicEditor();
myNicEditor2.setPanel(‘myNicPanel2’);
myNicEditor2.addInstance(‘myInstance2’);
}
}
</script>
<div id=”sample”>
<div id=”myNicPanel” style=”width: 525px;”></div>
<div id=”myInstance1″ style=”font-size: 16px; background-color: #ccc; padding: 3px; border: 5px solid #000; width: 400px;”>
You can edit here …
</div>
</div>
<br/>
<br/>
<div id=”editthis”>
This text should be in edit mode with NicEditor above this text when I click the button below
<input type=”button” value=”Click Me” onClick=”editProcess(‘edit.php’,’editthis’);” />
</div>
This is the page that will replace into #editthis (edit.php):
[CODE]
<div id=”myNicPanel2″ style=”width: 525px;”></div>
<div id=”myInstance2″> Edit This </div>
And this is the Ajax (ajax.js):
[CODE] var xmlHttp = buatObjekXmlHttp();
function buatObjekXmlHttp()
{
var obj = null;
if (window.ActiveXObject)
obj = new ActiveXObject(“Microsoft.XMLHTTP”);
else
if (window.XMLHttpRequest)
obj = new XMLHttpRequest();
// Cek isi xmlHttp
if (obj == null)
document.write(
“Browser tidak mendukung XMLHttpRequest”);
return obj;
}
function ambilData(sumber_data, id_elemen)
{
if (xmlHttp != null)
{
var obj = document.getElementById(id_elemen);
xmlHttp.open(“GET”, sumber_data, true);
xmlHttp.onreadystatechange = function ()
{
if (xmlHttp.readyState == 4 &&
xmlHttp.status == 200)
{
obj.innerHTML = xmlHttp.responseText;
}
}
xmlHttp.send(null);
}
}
Please help…