Clear CKeditor form after submission

I am creating a CKeditor instance for some content management and after submission would like to clear the input field automatically.
I am posting the form contents using jQuery if this makes and difference.
Who is Participating?
dagaz_deConnect With a Mentor Commented:
Ok then you must use a Command to reset the value like this:

are you using CKEDITOR 3.0?

then you must use the setData method;

CKEDITOR.instances.editor1.setData( '' );

more information u can get Here:

Mark BradyPrincipal Data EngineerCommented:
Does your form use php session() ? If so, you can kill the session like this:


Run that line in php script to destroy session and data inside session so won't show up in your form anymore.

If not:

Javascript will get rid of the values. Just rename the variables in my function and add more to suit your form.
Place this in between the <head> and </head> tags on your page.

<script language="javascript">
function  clearForm()
document.getElementById('name').value = '';
document.getElementById('email').value = '';
document.getElementById('address').value = '';
document.getElementById('phone').value = '';
// keep going untill all your form input fields are empty. Replace the values inside the quote marks with the "name" value on each of your form elements.

To run the script, you could add some code to the end of your submit button or add it to some other process. Here's an example.

<input type='button' onclick="document.forms.MyForm.submit(),clearForm()" />

Although, this would work, it is not a good idea to put the code on your submit button in case there is an error with data in the form you will need to alert the user and have them fix it. You don't want them to have to refill out the form each time!

Hope this helps. If not, can you be more specific on what fields you have on your form and how you are submitting it. Perhaps post your form code here or attach it.
LmillardAuthor Commented:
Thanks for coming back so quickly.
I am using Coldfusion so no access via the php method.

I have already tried clearing the input using traditional javascript getElementById but this does not seem to clear the field, not sure why. It clears all fields up to the text area that is being used by CK but not the text area itself.
I am posting the code below for all to see.

<form id="theForm">
<input type="hidden" name="NewRec" value="#NewRec#" />
<input type="hidden" name="BlogId" value="#Url.BlogId#" />

<cfif Not NewRec>
<input type="hidden" name="bUrl" value="#bUrl#" />

<table align="center" border="0" width="100%">
    <td>Enter Post Title</td>
    <td width="7px"><img src="#Application.BoPath#Assets/Img/backoffice/mand.png" alt="" /></td>
    <td><input type="text" name="BlogTitle" id="BlogTitle" value="#BlogTitle#" style="width:515px" /></td>
    <td>Select a Catagory</td>
    <select name="BlogCat" id="blogCat">
    <cfif ThisBlogCat.RecordCount is 0>
    <option value=""></option>
    <option value="#ThisBlogCat.CatId#">#ThisBlogCat.CatDesc#</option>
    <cfloop query="AllBlogCat">
    <option value="#AllBlogCat.CatId#">#AllBlogCat.CatDesc#</option>
    <td>Posted By</td>
    <td ><img src="#Application.BoPath#Assets/Img/backoffice/mand.png" alt="" /></td>
    <input type="text" name="UsrSynom" size="20" id="UsrSynom" value="#UsrSynom#" />
    Display on Live Website?
    <select name="Status">
    <cfswitch expression="#Status#">
    <cfcase value="1">
    <option value="1">Show on live site</option>
    <option value="0">Hide from live site</option>
    <option value="0">Hide from live site</option>
    <option value="1">Show on live site</option>
    <td>Website Url</td>
    <cfif NewRec>
    <td><img src="#Application.BoPath#Assets/Img/backoffice/mand.png" alt="" /></td>
    <td><input type="text" name="bUrl" size="50" id="bUrl" value="#bUrl#" style="width:315px" /></td>
	<td><a href="#FullPostPath#" target="_blank" title="View link in new tab">#Application.BoPath#blog/posts/#bUrl#.cfm</a></td>

<div style="padding-top:10px;">
		<textarea cols="100" id="editor1" name="BlogContent" rows="10">#blogContent#</textarea>

		<script type="text/javascript">
			// Replace the <textarea id="editor1"> with an CKEditor instance.
			CKEDITOR.replace( 'editor1',
					toolbar :
					uiColor : '##eee',
    			    filebrowserUploadUrl : '../fileUploadMulti/ckUpload.cfm'

		<div id="eMessage">

<div style="width:100%; padding-top:10px; text-align:right">
<cfif NewRec>
    <input type="submit" name="submit" class="button" value="Create Post" />
    <input type="submit" name="submit" class="button" value="Apply Changes" />

<div id="searchresults" style="text-align:left"></div>



        <cfinvoke component="#Application.CompPath#Blog" method="Create"

        <img src="#Application.BoPath#Assets/Img/backoffice/bulletpoint.png" alt="BulletPoint" />
        <p class="header2">Thank you, your blog post has been created</p>
            document.getElementById('BlogTitle').value = '';
            document.getElementById('BlogTitle').value = '';
			document.getElementById('blogCat').value = '';
			document.getElementById('bUrl').value = '';

Open in new window

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Mark BradyPrincipal Data EngineerCommented:
For the textarea it should be

var tArea = document.getElementById('editor1');
tArea .value = '';

That should wipe it out.
LmillardAuthor Commented:
Not working for some reason, I'm no expert with js but I'm totally sure I have it all typed correctly and in the right place as all the fields are cleared other than the CKeditored text area.
If you are using COLDFUSION wich version do u have? If 8 or higher its simple - just one tag for an FCK Editor:

<cfform name="form1">
  <cftextarea name="textarea1" height="400" width="480" richtext="yes" toolbar="Basic" skin="silver" toolbaronfocus="yes" value="#YOUR_VALUE#"></cftextarea>

Here’s how you can set the value of the editor using client side JavaScript.

This is not a documented feature though.

var editorinstance = ColdFusion.objectCache['nameoftextarea'];

var editor = FCKeditorAPI.GetInstance(editorinstance.richtextid);


If you have Version 7 or earlier - let me know because i have an component for U
LmillardAuthor Commented:
I wish I had know that CF has the ability to create the form using cfforms but unfortunately I am too far in to be able to switch to this method but can consider this for future versions on my application.
I am using CF9 so should have the full functionality in place to do this.
I am using the newer CK editor, I presume its all the same as the older FCK.
theres no problem if you switch to cfform instead of a form tag.  Your can keep your old form elements! just change your tag <form .... to <cfform ...... (and the end tag too, of course)
then make a textarea like <cftexarea and you'll see It will do everthing for you.

Tell me if it works for You.
LmillardAuthor Commented:
this code runs in many places in applications that are distributed so I really do need to go with a non cfform option at the moment but will definitely be considering a measure code change across the board in the future
LmillardAuthor Commented:
Thanks so much that has worked perfectly. Also thanks for the CF tip, I will be moving over to this asap!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.