FIX: Index Parameter for the Add Method Behaves Differently for Options and Areas Collections (208534)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.01 SP1
  • Microsoft Internet Explorer (Programming) 4.01 SP2

This article was previously published under Q208534

SYMPTOMS

The options and areas collections are both 0-based collections; however, in Internet Explorer 4.x, the Add methods of these collections behave differently. This may cause compatibility issues.

CAUSE

In Internet Explorer 4.x, the Add method uses a 1-based index for the areas collection but a 0-based index for the options collection.

RESOLUTION

To resolve this problem, upgrade to Internet Explorer 5, in which both collections use a 0-based index.

STATUS

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

This bug was corrected in Internet Explorer 5.

MORE INFORMATION

The following code adds the new option to the second position of the options collection. However, it adds the new area to the first position of the areas collection.
<HTML>
<HEAD>
<TITLE>Area Collection Bug</TITLE>
<SCRIPT>
//Add to Area collection.
function Add2Area()
{
    var y = document.createElement("area");
    y.coords = "8,80,8,80"; 
    catfish.areas.add(y, 1);
    Populate();
}

//Add to Option collection.
function Add2Options()
{  
    var y = document.createElement("option");
    y.text = "newone";
    selects.options.add(y, 1);
    Populate();
}

function Populate()
{
    var s  = "";
    var x = catfish.areas
    for (var k=0;k<x.length;k++) 
         s += "Area " + k + ": " + x[k].coords + "<BR>";
    Areas.innerHTML = s;
    
    s  = "";
    x = selects.options;
    for (var k=0;k<x.length;k++) 
         s += "Option  " + k + ": " + x[k].text + "<BR>";
	Options.innerHTML = s
}
</SCRIPT>
</HEAD>

<BODY onload=Populate()>
<BUTTON onclick=Add2Area()>Add to area (index 1)</BUTTON><BR>
<IMG height=100 src="catfish.jpg" width=100 useMap=#catfish>
<MAP name="catfish">
<area shape="RECT" coords="445,12,468,102">
<area shape="RECT" coords="430,17,434,21">
</MAP><BR>
<div id=Areas></div>

<BR><BR>

<BUTTON onclick=Add2Options()>Add to option (index 1)</BUTTON><BR>
<SELECT id=selects>
	<OPTION>aaa</OPTION>
	<OPTION>bbb</OPTION>
</SELECT>
<BR>
<div id=Options>

</BODY>
</HTML>
				

REFERENCES

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbBug kbDHTML kbfix kbie500fix KB208534