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.


    {% if trans != "" %}
        <div id="sTransContainer">
            <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>
    {% endif %}

My copy.js

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

Read more here:

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: