jquery get selected text from text input
- By Preneesh AV --
- 21-Apr-2019 --
- 129 Comments
This jquery script opens a alert box when text is selected inside a text input box in form. This helps to fetch value of selected text and display selected text in another part of website.
$( ":input" ).select(function() {
console.log( "Something was selected" );function disp() {
var text = document.getElementById("train-1-chattext");
var t = text.value.substr(text.selectionStart, text.selectionEnd - text.selectionStart);
alert(t);
}
disp();