Search code examples
javascriptjquerycontenteditablerte

How do I get the html from a contentEditable div to go inside of a hidden text form element?


I don't believe that you can use the input straight from a content editable div and submit it in a form, so I figured that I could just have a hidden text field and do something like this:

var blog_post = $("#editable_div").html();
$('#hidden_text_area').val(blog_post);

Does anyone know of a way to do this? It is not working with what I have. I thought that maybe the $('#hidden_text_area').val(blog_post); needed to be triggered by an event, but I tried it with a click and it didn't work.

$('#clicker').click(function(){
  $('#hidden_text_area').val(blog_post);
})

Solution

  • Try:

    $('#clicker').click(function(){
     var blog_post = $("#editable_div").html();
     $('#hidden_text_area').val(blog_post);
    })
    

    Because it does not look like your blog_post variable contains the html content when you click this button.