I would like to take input from a text box, concatenate its value with a string, then copy it to the clipboard.
I get stuck at .select()
, because it doesn't work with the variable. I inserted the alert
before .select()
to check its value, but that's okay. The alerted value should be copied to the clipboard.
function copyLink() {
var siteNumber = document.getElementById("number");
var home = "http://www.website.com/site";
var link = home.concat(siteNumber.value);
alert(link);
link.select();
document.execCommand("copy");
alert("Copied the text: " + link);
}
<input type="text" id="number">
<button onclick="copyLink()">Copy input as link</button>