Reputation: 1619
I have this tinymce text area which is using Ajax to call it and call the content from the database
<form class="form">
<table cellspacing="20">
<tr>
<td>
<label>Select Page :</label>
</td>
<td>
<select name="cms" id="cms" onchange="page_get_content(this.options[selectedIndex].value);">
<option value="">Select Page to be edited</option>
<option value="3">Home Page</option>
<option value="1">About us</option>
<option value="2">Agents</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td>
<div id="content" style="display: none;">
<textarea id="newsdesc" name="content"></textarea>
</div>
</td>
</tr>
</table>
</form>
Here is the JavaScript that calls it
function page_get_content(id) {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('content').style.display = "block";
document.getElementById('newsdesc').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET', 'forms/cms_get.php?page_id=' + id, true);
xmlhttp.send();
}
And here is the cms_get.php:
<?php
$page_id = $_GET['page_id'];
if(!empty($page_id)){
$cms = new CMS();
$page = $cms -> find_by_id($page_id);
if($page) {
?>
<?php echo $page -> content; ?>
<?php
}
}
?>
Everything is working fine but the tinymce is loading empty, and when i inspect the element with fire bug i get my text area but it is hidden and i tried to display it as block it is showing me the regular html text area my point is i want to show it with the contents in it
Upvotes: 2
Views: 3086
Reputation: 11931
Don't edit the .innerHTML
, rather use tinyMCE.get(id).setContent(text);
More info: http://www.tinymce.com/wiki.php/API3:method.tinymce.Editor.setContent
Upvotes: 3