JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" value="Hi" id="NMR_txtusername" />
<button id="myId" onclick="copyUser();">Copy
</button>
JavaScript
function copyUser(){
var copyText = document.getElementById('NMR_txtusername');
copyText.select();
console.log(copyText);
document.execCommand("copy");
console.log('copy success', document.execCommand('copy'));
alert("Copied the text: " + copyText.value);
}