SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Wallingford, CT
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting the value of a CKEditor instance

    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.

  2. #2
    SitePoint Member
    Join Date
    May 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    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;
    	}
    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);
    This feels extraordinarily hackish...but it works well.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •