1

I have create a rich text editor using DIV as editor container. How can I pass the DIV value to textarea? I already use jquery code. it success when I view it live but when I submit the form, the textarea value is empty. Here is my code:-

HTML

<div id="rte" contenteditable="true" unselectable="off">
</div>
<textarea name='rteHide' id='stage'></textarea>

JQuery

$(function() {
$("#rte").keyup(function() {
    var content = $('#rte').html();
    $("#stage").text(content);
});
});

I'm using this for wordpress plugin. Please let me know if there any other way to pass DIV value without using .post() jquery. Or using textarea as rich text editor container.

I required to create this editor instead using the current existing rich editor because we want to do enhancement in future.

Thanks in advance.

Nad
  • 83
  • 1
  • 3
  • 7

1 Answers1

0

Try to use val() instead of text() to set the value of your textarea

$("#stage").val(content);

Also, to make sure that there's no conflict happen here, you can wrap your code inside:

jQuery(document).ready(function($) {
    $("#rte").keyup(function() {
        var content = $('#rte').html();
        $("#stage").val(content);
    });
}); 
13ruce1337
  • 753
  • 1
  • 6
  • 13
Felix
  • 37,892
  • 8
  • 43
  • 55
  • thanks. but still cannot post the value...even i'm using .val(), .text() and .html(). I can view the inserted data when i'm typing but when i clicked submit, the textarea is empty. – Nad Mar 14 '14 at 03:58
  • Can you post the code where you retrieve the textarea value? – Felix Mar 14 '14 at 04:03
  • I;m using wordpress. Here is code to save the textarea data: function page_style_postdata( $post_id ) { $page_style_post=htmlspecialchars($_POST['rteHide']); update_post_meta($post_id, 'testnewmeta', $page_style_post ); } add_action( 'save_post', 'page_style_postdata' ); – Nad Mar 14 '14 at 04:17