Ashkan AA
Ashkan AA

Reputation: 33

Error in Asp .net: Uncaught ReferenceError: HTMLButtonElement

I write this java script code for copy "txid" to the clipboard but i have this error: Uncaught ReferenceError: HTMLButtonElement this is my function:

function txidButtonCopy(txid) {
            
            var copyText = document.getElementById("txid");

            
            copyText.select();
            copyText.setSelectionRange(0, 99999); /* For mobile devices */

            
            navigator.clipboard.writeText(copyText.value);

            
            alert("txid");
        }

another part of code:

function txidButton(txid) {
            var disabled = 'disabled';

            if (txid!='') {
                disabled = '';
            }
            return '<button onclick="txidButtonCopy(' + txid + ')" ' + disabled + ' title="لینک تراکنش" class="btn btn-info" style="margin: 5px;"><i class="ion ion-ios-copy-outline"></i></button>';
        }

Upvotes: 0

Views: 51

Answers (1)

Matthew Martens
Matthew Martens

Reputation: 11

You are grabbing the html button element by id when the element has no id. Give the element an id, or use document.getElementsByClassName.

function txidButton(txid) {
        var disabled = 'disabled';

        if (txid!='') {
            disabled = '';
        }
        return '<button id="txid" onclick="txidButtonCopy(' + txid + ')" ' + disabled + ' title="لینک تراکنش" class="btn btn-info" style="margin: 5px;"><i class="ion ion-ios-copy-outline"></i></button>';
    }

Upvotes: 1

Related Questions