I tried to copy by pressing a button, copy the value of input hidden. In JavaScript the value is obtained in var without problems, but it does not copy the value. What am I doing wrong?
<div class="dropdown-divider"></div>
<a class="dropdown-item" onclick="mycopyphone()">Copiar Telefono</a>
<input type="hidden" id="Key" value="'. $row["telefono"] .'" />
<script>
function mycopyphone() {
var hidden = document.getElementById("Key").value;
copyText = hidden;
copyText.select();
copyText.setSelectionRange(0, 99999)
document.execCommand("copy");
alert("Copied the text: " + copyText.value);
}
</script>