JSFiddle - React, Tailwind, and code Playground
HTML
<textarea>Some default text; HUlk is very cool innit</textarea>
<br/>
<input type="text" id="hulk" />
JavaScript
$('textarea').on('select', function() {
var foo = getSelectionText();
$('#hulk').val(foo);
});
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}