JSFiddle - React, Tailwind, and code Playground

HTML

<table>
<tr>
  <td>Test code 1</td>
  <td><input type='text' id='input1' /></td>
</tr>
<tr>
  <td>Test code 2</td>
  <td><input type='text' id='input2' /></td>
</tr>
</table>

JavaScript

var t = '';
function gText(e) {
    t = (document.all) ? document.selection.createRange().text : document.getSelection();

    document.getElementById('input1').value = t;
}

document.onmouseup = gText;
if (!document.all) document.captureEvents(Event.MOUSEUP);