function disp() { var text = document.getElementById("text"); var t = text.value.substr(text.selectionStart, text.selectionEnd - text.selectionStart); alert(t); }