Это должно работать для вас:
<script>
function myFunction() {
let inputEl = document.getElementById("myInput");
inputEl.select(); // Select element
inputEl.setSelectionRange(0, inputEl.value.length); // select from 0 to element length
const successful = document.execCommand('copy'); // copy input value, and store success if needed
if(successful) {
alert("Copied the text: " + inputEl.value);
} else {
// ...
}
}
</script>
Редактировать: Чтобы уточнить и исправить некоторые другие мелкие ошибки: