I need to copy the value from the input field to the clipboard. Instead of getting the value of the input field I get null.
Here is my Code:
<input type="text" value=${model.anchor_url} id=${properties.anchor_name}>
<button class="c-button" onclick="myFunction()">
    <span class="c-button__label">Copy</span>
</button>
<div data-sly-test="${model.anchor_url}">
    <p>URL from Model :</p>
    <pre>${model.anchor_url}</pre>
</div>
function myFunction() {
    const field = document.getElementById(`${properties.anchor_name}`);
    navigator.clipboard.writeText(field);
    alert("Copied the text to clipboard: " + field);
}
The value for field variable results null even though the id exist and it has a value.
 
     
    