I am working on a project to automate copying text. However, what I would like to do is just have a button that the user can click that will put a specified text to the clipboard.
I am able to do this now by copying text from a text area, however, I am trying to remove the need for a text area and just have a button.
Once pressed it will put text into the clipboard based on the buttons value.
For instance, the below posted snippet has a text area that the button will copy. I want to just have the button, no text area, and once pressed it will copy the name of the button to the clipboard
<textarea id="alu1" rows="1" border="none" style="width:70%; height: 10px">
ssh -l admin:admin x.x.x.x
</textarea>
<button id="alu1copy" style="width: 50px; height: 20px">ssh -l admin:admin x.x.x.x</button>
<script>
var input1 = document.getElementById("alu1");
var button = document.getElementById("alu1copy");
button.addEventListener("click", function (event) {
event.preventDefault();
input1.select();
document.execCommand("copy");
});
</script>