Deselecting text in input text box
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Deselecting text in input text box

From: <len.hartley@gmail.com>
Date: Mon Feb 27 2006 - 19:05:46 CET

I have a text input box and I don't want the text to be selected either
when the user tabs to the item or if the user clicks on it.

Now the function below which I found from 2002 in the archive works
fine for IE 6 but it works in neither Netscape 7 nor Firefox 1.0.

I'm hoping some of you might have an alternative suggestion or insight
for Netscape and Firefox.

Code that works in IE6:

function clearSelection () {
  if (document.selection)
         document.selection.empty();
  else if (window.getSelection)
         window.getSelection().removeAllRanges();
}

<input type="text" name="theElt" onfocus="javascript: clearSelection()"
size="12" maxlength="20" readOnly style="margin: 7px 3px 0px 3px;
border: 0px;" />
Received on Mon May 1 03:39:54 2006