javascript get selected text from input code example
Example 1: get selected text js
// Get highlighted text this way:
window.getSelection().toString()
Example 2: get selected text input javascript
function disp() {
var text = document.getElementById("text");
var t = text.value.substr(text.selectionStart, text.selectionEnd - text.selectionStart);
alert(t);
}