Connecting Tech Pros Worldwide Help | Site Map

How do I know the whole text of an INPUT element is selected

datactrl
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi, all

How do I know the whole text of an INPUT element is selected?

Jack


Andrew Thompson
Guest
 
Posts: n/a
#2: Jul 23 '05

re: How do I know the whole text of an INPUT element is selected


On Mon, 7 Jun 2004 21:27:38 +1000, datactrl wrote:
[color=blue]
> How do I know[/color]

...look at it,
[color=blue]
>..the whole text of an INPUT element is selected?[/color]

...it is blue background w/ white text (on windows).

How is that a JS question? ;-)

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Ivo
Guest
 
Posts: n/a
#3: Jul 23 '05

re: How do I know the whole text of an INPUT element is selected


"datactrl" wrote[color=blue]
> How do I know the whole text of an INPUT element is selected?
>[/color]

<script>
function isselect(){
if (document.getSelection)
return document.getSelection(); // if NS
if (document.selection && document.selection.createRange)
return document.selection.createRange().text; // if IE4+
return false;
}
function test(){
var a=document.forms[0].elements['thetext'].value;
var b=isselect();
if(a==b) alert('Selected all!');
else if(b) alert('Selected:\n'+b);
else alert('Naught selected.');
}
</script>
<form>
<input type="text" name="thetext" value="select me">
<input type="button" value="Click me" onmousedown="test()">
</form>

HTH
Ivo



datactrl
Guest
 
Posts: n/a
#4: Jul 23 '05

re: How do I know the whole text of an INPUT element is selected


Thanks Ivo, it's a good help.

Jack


Closed Thread