On my ASP.Net website, I am incorporating basic Javascript functionality.
One particular task involves calculating a value and saving it in a hidden textbox, like this:
<asp:LinkButton ID="LinkButtonShare" runat="server" CssClass="btn btn-success" OnClientClick="copyToClipboard()"><i class="fa fa-share-square"></i> Share</asp:LinkButton>
<div class="hidden"><asp:TextBox ID="TextBoxCopyURL" runat="server" ClientIDMode="Static"></asp:TextBox></div>
Afterwards, the Javascript function below is executed.
function copyToClipboard() {
var copyText = document.getElementById("TextBoxCopyURL");
copyText.select();
document.execCommand("copy");
/* Alert with the copied text */
alert("Copied the text: " + copyText.value);
Despite receiving an alert, the text string is not being copied to the clipboard in Firefox or Chrome, resulting in an issue illustrated in the image below:
https://i.sstatic.net/nzdoR.png
I am struggling to identify the issue with such a seemingly straightforward task.