开发者

Unable to retrieve a textarea's value

I've constructed a basic form in which there are certain elements, one of which is a textarea element. The whole form is enclosed in a div, and when the user clicks the submit button the form is hidden and the value of the textarea should be shown for review.

I am using jQuery to retrieve the data in the textarea, but have also tried without it but to no avail. I have tried using .text(), .val() and .html(). None of which work, even though .val() should be.

Here's the script I'm currently using:

$(function(){
    var ptext = $('#post_text');
    $('#submit').click(function() {
        data = ptext.val();
        alert(data);
        $('#form_container').fadeOut('slow', function(){
               $('#status').html(data);
               return;
       });
       $('#status').fadeIn('slow');
       return true;
    });
});

...and the textarea from the form

<div id="post_box"><textarea id="post_text" name="text" class="full开发者_StackOverflow社区"></textarea></div>

Additonal info: I'm using CKEditor on the textarea, but I do not think it would cause any problems like this. Have also tested in IE8 and Chrome.

Any ideas?


Of course it's CKEditor that causes this. The textarea is not a textarea at all any more, it has been replaced by something else, probably an iframe. As the textarea doesn't exist any more, you can't use the val method to get it's text.

Use the getData method to get the text from the editor:

var data = CKEDITOR.instances.post_text.getData();


It has to be because of CKEditor, because your code for grabbing text from textarea is valid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜