function cloneText(){
var copyText = document.getElementById("myInput");
copyText.select();
copyText.setSelectionRange(0, 99999)
document.execCommand("copy");
alert("Copied the text: " + copyText.value);
}<input type="text" id="myInput"/>
<input type="button" onclick="cloneText"/>