View Full Version : getselection() - textselection?

03-02-2008, 12:49 AM
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

03-02-2008, 05:58 PM
No one?

03-02-2008, 06:05 PM

Looks like you'll have to have browser specific code as there are different techniques for IE vs Firefox

03-02-2008, 06:08 PM
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...

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>
<form action="#" method="get">
<textarea id="select" cols="40" rows="5">1234567890
<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;