View Full Version : getselection() - textselection?
I know how to use this function...
But I only want this function to work on a textarea...
How would I do that!? Also I've tried like document.textname and also getElementById please help! :o
Medyman
03-02-2008, 06:05 PM
http://www.squarefree.com/2006/05/06/finding-the-textarea-selection/
Looks like you'll have to have browser specific code as there are different techniques for IE vs Firefox
Thanks So Much!
But when I do selectionEnd it just prints out how many characters I put..
Felix Riesterer
03-15-2008, 11:52 AM
Why don't you explicitly say for which browser you need which functionality?
You have already been given a hint that there are major differences between the different browsers' implementations of the selection mechanism...
Master_script_maker
03-15-2008, 01:43 PM
this code will check what text is selected in the text box every .2 seconds and output it to a span.
<span id="output">No Text Selected</span>
<hr>
<form action="#" method="get">
<textarea id="select" cols="40" rows="5">1234567890
abcdefghijklmnopqrstuvwxyz</textarea><br>
</form>
<script type="text/javascript">
var int=setInterval(check, 200);
function check() { document.getElementById("output").innerHTML = getSelectionInfo(); }
function getSelectionInfo()
{
var rv = "";
var x;
x = document.getElementById("select");
if(!document.selection) { //if not IE
rv = x.value.substr(x.selectionStart, x.selectionEnd - x.selectionStart);
} else {
rv = document.selection.createRange().text;
}
if (rv == null || rv == "") {
rv="No Text Selected";
}
return rv;
}
</script>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.