Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

BUG: The FOR Attribute of the LABEL Object Resets Focus


View products that this article applies to.

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.

↑ Back to the top


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>
				

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

Steps to Reproduce the Problem

In following the drop-down list box, the third element is selected. If you click the Citizenship Status Label, the selected element in the drop-down list is reset to the first element.
<html>
<BODY>
<LABEL for='test'>Citizenship Status:</LABEL>

<SELECT NAME='test' ID='test'>
<OPTION VALUE="3" >Alien Perm
<OPTION VALUE="4">Alien Temp
<OPTION VALUE="1" SELECTED >Native
<OPTION VALUE="2">Naturalizd
<OPTION VALUE="N">Not Indic.
</SELECT>

</BODY>
</HTML>
				

↑ Back to the top


References

For more information about developing Web-based solutions for Internet Explorer, visit the following Microsoft Web sites:
Internet Explorer Web Site: For information about the properties and events that this article uses, visit the following Microsoft Web sites:

↑ Back to the top


Properties

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

↑ Back to the top


Keywords: KB314279, kbnofix, kbbug

↑ Back to the top

Article Info
Article ID : 314279
Revision : 3
Created on : 5/21/2007
Published on : 5/21/2007
Exists online : False
Views : 480