1

I can't copy value from textarea in the first click.

im working with Popup Box.

i think the problem is im hidding the .footer-result-box for textarea.

im using code like this :

HTML :

<div id="popup-box">
    <div class="footer-result-box" style="height:0px">
    <textarea id="final-interest"></textarea> //textarea
    </div>

    <button class="btn-copy-all"> COPY </button> //copy button
</div>

jQuery :

$(".btn-copy-all").click(function() {
    //im use this code for get value from table when row selected.
    if (states.activeScreen == "interest") {
        var datas = new_tabel_interest.rows(".selected").data();
    }

    if (states.activeScreen == "related") {
        var datas = new_tabel_page_interest.rows(".selected").data();
    }
    res = "";
    for (i = 0; i < datas.length; i++) {
        if (res != "") res += ",";
        res += datas[i][2];
    }

    //EXECUTE
    $("#final-interest").val(res); //texarea get value from selected row

    $(".footer-result-box").animate({
        height: "205px"
    }); //display box 

    $("#final-interest").select(); //select textarea value
    document.execCommand('copy'); //copy the result

    $("#popup-box").css({
     display: "none"
    }); //close popup-box

    alert("Copied!");
});

The code running well, but the result not copied.

My Goal :

  • Success copy textarea value then close the #popup-box.

Textarea Value will get DATA from Table when im select the row table.

Calvin Ananda
  • 1,140
  • 10
  • 28
  • 2
    What is the code that checks if data is not copied to the clipboard? – guest271314 Jan 16 '18 at 02:30
  • textarea will get value from selected row table. sorry i will not discuss about table. Essentially, I've managed to display the value on the textarea. but cant copy the value when button is clicked. – Calvin Ananda Jan 16 '18 at 02:35
  • 1
    You have not posted an [mcve], so it's impossible to test this theory - but since you're (probably) redeclaring `datas` as locally scoped in both if statements the changes are having no effect on the "real" `datas`, which is presumably declared somewhere else. – Tibrogargan Jan 16 '18 at 02:35
  • 1
    This [**Codepen**](https://codepen.io/Bes7weB/pen/GyXNoW) works... It is *slightly* different from your code... But your strange way to show/hide an element, while questionnable, is supposed to be working. – Louys Patrice Bessette Jan 16 '18 at 02:46
  • `#popup-box` hey? I'm pretty sure that this popup DOES NOT exist on code parsing. Use delegation. – Louys Patrice Bessette Jan 16 '18 at 02:57
  • Possible duplicate of [Event binding on dynamically created elements?](https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) – Louys Patrice Bessette Jan 16 '18 at 02:58

0 Answers0