Simple click to copy button to copy value of textbox to clipboard.
//Add this function inside head tag
<script>
function copyText() {
/* Get the text field */
var copyText = document.getElementById("myInput");
/* Select the text field */
copyText.select();
/* Copy the text inside the text field */
document.execCommand("copy");
/* Alert the copied text */
alert("Copied");
}
</script>
//Inside html file
<textarea value="" id="myInput" rows="1" cols="75">This value will be copies</textarea>
//Button to trigger copy action
<button onclick="copyText()" class="btn btn-sm btn-primary">Copy link</button>
Comments
Post a Comment