469,343 Members | 5,380 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

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

Hi, all

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

Jack
Jul 23 '05 #1
3 1239
On Mon, 7 Jun 2004 21:27:38 +1000, datactrl wrote:
How do I know
...look at it,
..the whole text of an INPUT element is selected?


...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
Jul 23 '05 #2
Ivo
"datactrl" wrote
How do I know the whole text of an INPUT element is selected?


<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

Jul 23 '05 #3
Thanks Ivo, it's a good help.

Jack
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by dmiller23462 | last post: by
5 posts views Thread by len.hartley | last post: by
7 posts views Thread by Chuck Anderson | last post: by
4 posts views Thread by Paul J. Lucas | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.