I have created table cell with copy text.. when I click copy it gets the value of particular ipno cell and post it to the input.. then I copy it into clipboard using execCommand.. It is working fine when I make input type as text.. but the problem is that it doesn't copy the value after I make input as hidden.. because I doesn't need to show input.. my table tr is as follow
<td align="center" ><span class = 'cpy'><?echo $row['ipno'];?></span> <span class="text-primary copytd"> Copy</span> </td>
and my input to copy ipno from table is
<input type="hidden" name = "ip" id="divcopy" />
and my jQuery and Javascript function to copy on clipboard is
$('.copytd').on("click",function(e) {
var copyText = $(this).closest('tr').find(".cpy").text();
// $("#divcopy").val(copyText);
$('input[name="ip"]').val(copyText);
var di = $("#divcopy").val();
myFunction();
// $(this).closest('tr').find(".copytd").text('Copied');
});
function myFunction() {
var copyT = document.getElementById("divcopy");
copyT.select();
copyT.setSelectionRange(0, 99999); /*For mobile devices*/
document.execCommand("copy");
alert("copied");
}
note: it is working fine when I make input as visible.