BUG: The FOR Attribute of the LABEL Object Resets Focus (314279)
The information in this article applies to:
- Microsoft Internet Explorer (Programming) 5
- Microsoft Internet Explorer (Programming) 5.5
- Microsoft Internet Explorer (Programming) 6 (SP1)
This article was previously published under Q314279 SYMPTOMS
When you click a label that is associated with a select box, the element that you selected in the select box is reset to the first element on the list.
RESOLUTION
You can only work around this problem in Internet Explorer 6 by using the onfocusin event. You can basically store the selected index into a temporary variable and reset the index to that variable when the select box obtains focus.
Use the following code as an example:
<HTML>
<HEAD>
<SCRIPT>
//Set a temp expando to store the current selectedIndex
function SelectOnFocusIn()
{
try
{
var eSrc = window.event.srcElement;
if (eSrc)
eSrc.tmpIndex = eSrc.selectedIndex;
}
catch (e)
{
HandleError(e, false);
}
}
//restore the selectedIndex
function SelectOnFocus()
{
try
{
var eSrc = window.event.srcElement;
if (eSrc)
eSrc.selectedIndex = eSrc.tmpIndex;
}
catch (e)
{
HandleError(e, false);
}
}
</SCRIPT>
</HEAD>
<BODY>
<LABEL for="test">Citizenship Status:</LABEL>
<SELECT NAME="test" ID="test" onfocusin="SelectOnFocusIn()" onfocus="SelectOnFocus()">
<OPTION VALUE="3">Alien Perm </OPTION>
<OPTION VALUE="4">Alien Temp </OPTION>
<OPTION VALUE="1" SELECTED>Native </OPTION>
<OPTION VALUE="2">Naturalized </OPTION>
<OPTION VALUE="N">Not Indic. </OPTION>
</SELECT>
</BODY>
</HTML>
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. REFERENCES
For more information about developing Web-based solutions for Internet Explorer, visit the following Microsoft Web sites:
MSDN Library and Web Workshop:
Internet Explorer Web Site:
For information about the properties and events that this article uses, visit the following Microsoft Web sites:
Modification Type: | Major | Last Reviewed: | 5/12/2003 |
---|
Keywords: | kbbug kbnofix KB314279 |
---|
|