JSFiddle - React, Tailwind, and code Playground
by Naveen Kumar
HTML
<input type="button" value="Select" onmousedown="selectCup(); return false">
<input type="text" id="select_text">
<br><br><br><input type="text" id="test" value="Sample Text in this textbox">
JavaScript
function selectCup() {
var search_text = document.getElementById("select_text").value;
var n = search_text.length;
var input = document.getElementById("test");
var input_text = input.value;
var x = input_text.indexOf(search_text);
var y = x+n;
input.focus();
input.setSelectionRange(x, y); // Highlights "Cup"
};