I am new to Javascript and am working with Ajax. I am building a content manager for my site, and I have an instance of CKEditor. I was wondering what the javascript would be to get the value of the textarea. Normally with a textarea I use formname.elementname.value. When I use that with the CKEditor I get a null value.
I wrote a custom function in ckeditor/ckeditor_php5.php:
/**
* Custom function for retrieving the data of the current editor instance
*
* @param string instance id
* @return string
*/
public function getData($id)
{
$js = "";
if (!$this->initialized) {
$js .= $this->init();
}
$js .= $this->returnGlobalEvents();
$script = "document.write('<div id=\\"temp_zone\\" style=\\"display: none;\\"></div>');"
. "$(document).ready(function(){"
. '$("input[type=\\'submit\\']").each(function(i, v){'
. "$('#' + v.id).click(function(){"
. "var data = CKEDITOR.instances.$id.getData();"
. "$('#temp_zone').html(data);"
. "});"
. "});"
. "});";
$js .= $this->script($script);
return $js;
}
Then, where I intialize the ckeditor instance,
$ckeditor = new CKEditor();
$ckeditor->BasePath = 'somepath/ckeditor.php';
$input_str = "<$type id=\\"$name\\" name=\\"$name\\""
. " rows=\\"$rows\\" cols=\\"$cols\\">"
. "$values</$type>";
$input_str .= $ckeditor->editor($name, $values, $configs);
$input_str .= $ckeditor->getData($name);
This feels extraordinarily hackish…but it works well.