Question : Get ckeditor textarea value with jquery

I need to get the value of an instance of ckeditor from jquery....not using ckeditors methods since they are not available on the page anyway.

I have tried many many things like:
$('#save').click(function(){
  alert($('#body').val());
});

Nothing I have tried works. I always get undefined as the response...and using jquery $.post or $.ajax or any other type of form submission tools completely ommits the #body value from the response. Help would be highly appreciated.

Answer : Get ckeditor textarea value with jquery

I wrote a custom function in ckeditor/ckeditor_php5.php:
[code]
      /**
      * 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;
      }
[/code]

Then, where I intialize the ckeditor instance,
[code]
$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);
[/code]

This feels extraordinarily hackish...but it works well.
Random Solutions  
 
programming4us programming4us