"Stefan Mueller" <seekware-remove-@yahoo.com> wrote in message
news:dmch7p$2buf$1@news.imp.ch...[color=blue]
> I've an input box
> <input type = "text" name = "MyInput" value = "">
>
> and a selection
> <select name = "MySelection" size = "1">
> <option value = "1">Entry 1
> <option value = "2">Entry 2
> </select>
>
> With
> document.MyForm.MyInput.focus();
> document.MyForm.MyInput.select();
>
> I can set the focus to the input box and select the whole text. But if I[/color]
set[color=blue]
> the focus to the selection box with
> document.MyForm.MySelection.focus();
>
> the text in the input box is still selected.
>
> How can I unselect this text?
> Stefan
>
> PS: One possibility would be to add a hidden input box and to set the[/color]
focus[color=blue]
> to this hidden box before I set the focus to the selection. But I think[/color]
this[color=blue]
> would only be a workaround.
>[/color]
Will this help?
<html>
<head>
<title>blur.html</title>
<script type="text/javascript">
function onloader() {
document.MyForm.MyInput.focus();
document.MyForm.MyInput.select();
}
function clearSelection () {
if (document.selection)
document.selection.empty();
else if (window.getSelection)
window.getSelection().removeAllRanges();
}
</script>
</head>
<body onload="onloader()">
<form action="" method="get" name="MyForm">
<input type="text" name="MyInput"
value="Hello World" onblur="clearSelection()">
<select name="MySelection" size="1">
<option value="1">Entry 1
<option value="2">Entry 2
</select>
</form>
</body>
</html>
Credit
URL:
http://groups.google.com/group/comp...._thread/thread
/871226cbeb74ae70/d3a48c14f66cc707?lnk=st&q=JavaScript+deselect+text &rnum=8&
hl=en#d3a48c14f66cc707