I wrote this code to copy multiple textareas’ content with a unique button, but only the first textarea is copied.
var copyText = document.getElementsByClassName("form-control")[0];
function myFunction() {
// Get the text field
// Select the text field
copyText.select();
copyText.setSelectionRange(0, 99999); // For mobile devices
// Copy the text inside the text field
document.execCommand("copy");
// Alert the copied text
alert("Copied the text: " + copyText.value);
///second
}
<textarea class="form-control" tabindex="0">something</textarea>
<button onclick="myFunction()">clickme</button>
<textarea class="form-control"tabindex="3" >something1</textarea>
<button onclick="myFunction()">clickme</button>
<textarea class="form-control" >something2</textarea>
<button onclick="myFunction()">clickme</button>
How can I resolve this issue so that multiple textareas are copied, instead?