0
Q:

button copy javascript

var copyTextarea = document.getElementById("someTextAreaToCopy");
copyTextarea.select(); //select the text area
document.execCommand("copy"); //copy to clipboard
3

  <!-- The text field -->
<input type="text" value="Hello World" id="myInput">

  
<!-- The button used to copy the text -->
<button onclick="myFunction()">Copy 
  text</button> 
1
<!DOCTYPE html>
<html>
 <head>
   <script>
     function paste() {
            var pasteText = document.querySelector("#text");
            pasteText.focus();
            document.execCommand("paste");

            pasteText.value = pasteText.value + pasteText.value;
        }
   </script>
  </head>
  <body>
    <input id="text">
    <button onclick="paste()">Paste</button>
   </body>
0

  function myFunction() {
  /* Get the text field */
  var copyText = document.getElementById("myInput");

  
  /* Select the text field */
  
  copyText.select(); 
  
  copyText.setSelectionRange(0, 99999); /*For mobile devices*/

  /* Copy the text inside the text field */
  document.execCommand("copy");

  
  /* Alert the copied text */
  
  alert("Copied the text: " + copyText.value);
} 
1

New to Communities?

Join the community