JSFiddle - React, Tailwind, and code Playground
HTML
<textarea id="quote" readonly>
sample text that can be copied into another textarea
</textarea>
<textarea contenteditable="false" id="output" name="selected"></textarea>
<div id="output2">
</div>
JavaScript
var quotearea = document.getElementById('quote')
var output = document.getElementById('output')
quotearea.addEventListener('mouseup', function(){
if (this.selectionStart != this.selectionEnd){ // check the user has selected some text inside field
var selectedtext = this.value.substring(this.selectionStart, this.selectionEnd)
output.innerHTML = selectedtext
}
}, false)