Amit Kumar Pandit
Amit Kumar Pandit

Reputation: 93

getting selected text in an input field in IE8 and above

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

Answers (2)

Amit Kumar Pandit
Amit Kumar Pandit

Reputation: 93

Finally I found the solution as, input.selection.createRange().text.

Upvotes: 0

nik
nik

Reputation: 2483

var input= document.getElementById("id_of_input");
var selectedtext=input.value.substring(input.selectionStart,input.selectionEnd);

Upvotes: 1

Related Questions