INFO: Text Selection in a Control Not Cleared on Blur Event
ID: Q231321
|
The information in this article applies to:
-
Microsoft Internet Explorer (Programming) version 5.0
SUMMARY
Generally it is expected that the selection in a control is cleared when the focus moves to a different control. But Internet Explorer 5.0 does not behave this way, enabling toolbar-like scenarios, such as clicking on the button, to manipulate the selection.
MORE INFORMATION
The following code demonstrates how to clear the text when the focus moves to another control, by setting the control to its own value in the onblur event.
Place the following code in an HTML file and view in Internet Explorer.
<HTML>
<HEAD>
<SCRIPT LANGUAGE=vbscript>
<!--
Sub window_onload
text1.value = "test"
text1.select
End Sub
Sub text1_onfocus
text1.select
End Sub
Sub text1_onblur
text1.value = text1.value
End Sub
Sub text1_onkeydown
Select Case window.event.keyCode
Case 13 '-Enter
button1.focus
Case Else
End Select
End Sub
Sub button1_onkeydown
Select Case window.event.keyCode
Case 13 '-Enter
text1.focus
Case Else
End Select
End Sub
-->
</SCRIPT>
</HEAD>
<BODY bgcolor=paleturquoise>
<P>
When setting focus from a text box to a button in Internet Explorer 5, the
text that was selected remains selected even though the focus is now on the
button.
</P>
<P>
To work around this, set the value of contents of the Text to itself.
This can be done by uncommenting code in <EM>onblur</EM> event of text1.
</P>
<P>
Text1
<INPUT id=text1 name=text1 tabindex=1></P>
<P></P>
<P>
Button
<INPUT id=button1 name=button1 type=button value=Button tabindex=2>
</P>
</BODY>
</HTML>
REFERENCES
For more information, please see the MSDN Web Workshop:
http://msdn.microsoft.com/workshop/default.asp
Additional query words:
IE4 IE5 change VBScript focus onblur onfocus
Keywords : kbDHTML kbGrpInet kbIE500
Version : WINDOWS:5.0
Platform : WINDOWS
Issue type : kbinfo