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. Link to comment https://forums.phpfreaks.com/topic/121927-solved-selecting-text-in-a-textarea/ 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'); } } Link to comment https://forums.phpfreaks.com/topic/121927-solved-selecting-text-in-a-textarea/#findComment-629239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.