Copy text from textarea to clipboard – Python

I'm trying to enable a Copy button that will copy the content from the textarea, I gave an example of my HTML file and JS, I tried in all ways but I didn't succeed. Thanks for your help.

My HTML

    {% if trans != "" %}
    <br>
        <div id="sTransContainer">
            <h1>Trans</h1>
            <textarea style="resize:none" cols="5" rows="10" id="sText">{{ trans }}</textarea>
            <div class="right btn-group">
                <button onclick="myFunction()">Copy text</button>
                <script async src="js/copy.js"></script>
            </div>
        </div>
    {% endif %}

My copy.js

function myFunction() {
  var copyText = document.getElementById("trans");
  copyText.select();
  copyText.setSelectionRange(0, 99999)
  document.execCommand("copy");
  alert("Copied the text: " + copyText.value);
}


Read more here: https://stackoverflow.com/questions/68461280/copy-text-from-textarea-to-clipboard-python

Content Attribution

This content was originally published by Dejo at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: