Link to home
Start Free TrialLog in
Avatar of elliottbenzle
elliottbenzle

asked on

using onChange or OnKeyDown with CKEditor

I'm trying to create a custom javascript function for CKEditor but am unable to find anything on where to place this function within the existing CKEditor script.

If I add my function to the main textarea it doesn't work, I think this is because that textarea gets replaced with the instance of CKEditor.

Has anyone had any luck getting a onChange event to fire a custom function in Javascript? os seen an example of how to do this?

Thanks
Avatar of TheQuietShadow
TheQuietShadow
Flag of United States of America image

You will probably need to create an instance of the object in your header, then call it with the onchange event in the body.
You will also want to make sure that your onchange event is not being called except when you want it to occur.
You should also note that your code is excluding the last character (or keyboard action).
"hello" apears as "hell" but if you type "hello " and then hit backspace it apears as "hello " where is should display as "hello".
ASKER CERTIFIED SOLUTION
Avatar of TheQuietShadow
TheQuietShadow
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leakim971
for info the textarea is hidden. It goal is to send on form submission the CKEditor code (equ of what you see on the screen)

You need to use the API : http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.event.html#on

someObject = CKEDITOR.instances.ID_OF_YOUR_TEXTAREA

someObject.on("change", function() {
     alert("Changed !");
});

Open in new window

Avatar of elliottbenzle
elliottbenzle

ASKER

The onKeyUp was very helpful. Thank you.
I'm sorry but this is not the right answer for CKEditor :o(
ths is incorrect for CKEditor .. but works for a plain textfield