user1360479
user1360479

Reputation: 13

Jhtmlarea - copying textarea content to another textarea using jquery

I'm trying to use below code to get text copied from jhtmlarea to another textarea but it do not work.

  <textarea id="attrArticleHtml"></textarea>
  <textarea id="attrArticleSecond"></textarea>

$(function() {
    $('#attrArticleHtml').keyup(function() {
        var textareaHtml = $('#attrArticleHtml').htmlarea('toHtmlString');
        console.log(textareaHtml);
        $('#attrArticleSecond').text(textareaHtml);

    });     
});

What ID I should use to get text copied using keyup? Seems that jhtmlarea is using iframe and therefore attrArticleHtml is not ok.

Upvotes: 1

Views: 1774

Answers (3)

speti43
speti43

Reputation: 3046

This worked for me:

 $("#ctl00_Kontent_taHtmlEditor").htmlarea({
    loaded: function() {
        var mycontrol = { jhtmlarea: this };
        $(mycontrol.jhtmlarea.editor.body).keypress(function(e) {
            var segedmezo = $("#divDrop").find("iframe").contents().find("body");
            $("#ctl00_Kontent_hfHtmlWithCodes").val(reduceCodes(segedmezo.html()));
        });
    },
    toolbar: [...

Upvotes: 1

Anton Baksheiev
Anton Baksheiev

Reputation: 2251

you need to add load to params of creation of area.

 $("#attrArticleHtml").htmlarea({
                loaded: function () {

                    $(this.editor).find('BODY').keyup(function (e) { 

                    var htmlValue =  $('#attrArticleHtml').val();
                    $('#attrArticleSecond').val(htmlValue )

        });

If this is usfull for you please dont forget click rep.

Upvotes: 0

Anton Baksheiev
Anton Baksheiev

Reputation: 2251

You should use VAL(), not HTML,TEXT. So you code has to be like this:

$(function() {
    $('#attrArticleHtml').keyup(function() {
        $('#attrArticleSecond').val($('#attrArticleHtml').val());

    });     
});

Upvotes: 0

Related Questions