Reputation: 93
How do I get the selected text in an input field in IE8 and above versions. I have tried using window.getSelection()
document.getSelection()
and document.selection.createRange().text
. Last one is returning empty string and the others are undefined in IE8.
Upvotes: 0
Views: 502
Reputation: 93
Finally I found the solution as, input.selection.createRange().text
.
Upvotes: 0
Reputation: 2483
var input= document.getElementById("id_of_input");
var selectedtext=input.value.substring(input.selectionStart,input.selectionEnd);
Upvotes: 1