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

I

Ivo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top