The Little Guy Posted August 29, 2008 Share Posted August 29, 2008 How can I get the text someone selects from a textarea? SO if they highlight (with their mouse) some text and press a button, an alert box will pop up showing what text was selected in the textarea. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 29, 2008 Author Share Posted August 29, 2008 function getSelText(){ var mbox = document.getElementById('message'); if (window.selection) { // for IE alert(document.selection.createRange().text); } else if (typeof mbox.selectionStart != 'undefined') { // for FF, Opera etc... alert(mbox.value.substring(mbox.selectionStart, mbox.selectionEnd)); } else { alert('Could not find selection'); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.