0

I am trying to write a code which allows my website users to save drafts. I am facing a problem while doing this.

HTML

<input type="button" value="SAVE DRAFT" onClick="saveit()">
<textarea id="content" name="content" class="widgEditor nothing">initial text</textarea>

JavaScript

function saveit() {
   var content = $('#content').val();
   alert (content);
   //some other ajax codes to save draft... 
}

When I click the Save draft button, it always shows initial text even if I change the text in the textarea (editor).

I have tired this with widgEditor and CKeditor but unfortunately I could not figure out how to fix this problem.

NOTE: When I try this without any WYSIWYG editor, it works properly but that text area needs to be an editor.

Can anyone help me with this?

Bojangles
  • 99,427
  • 50
  • 170
  • 208
kaya
  • 41
  • 1
  • 11
  • By the way, I have found this jquery plugin which exactly does what I want. http://www.fyneworks.com/jquery/CKEditor/ – kaya Sep 14 '11 at 22:15

2 Answers2

2

This could probably help if you use CKEditor:

Using jQuery to grab the content from CKEditor's iframe

Essentially, you use this before you read the value:

for ( instance in CKEDITOR.instances )
        CKEDITOR.instances[instance].updateElement();

Also I think you should use .text(), not .val() when working with textareas.

Community
  • 1
  • 1
brain
  • 2,507
  • 1
  • 13
  • 12
0

Don't use onClick

$(':button').click(function() { 
    var content = $("#content").val();
   alert( content );
   //some other ajax codes to save draft...  
});

works fine

http://jsfiddle.net/KEtMC/

Steve Robbins
  • 13,672
  • 12
  • 76
  • 124