My client asked me (a js client side programmer) to change the order of the options so that their company's option appears at the top of a select box when the page loads.
The following code works in FF but fails in IE7 when I try to swap two options:
function load{
var shippingLocation = document.getElementById("location");
var swap = null;
var initiallyFirstItem = shippingLocation.options[0].cloneNode(true);
var lastPos = null;
for(var i = 0; i < shippingLocation.length; i++)
{
if(shippingLocation.options[i].value == "XETEX")
{
swap = shippingLocation.options[i];
lastPos = i;
break;
}
}
console.debug("sl: " + shippingLocation.options[0]);
console.debug("s: " + swap);
shippingLocation.options[0] = swap;
shippingLocation.options[lastPos] = initiallyFirstItem;
shippingLocation.selectedIndex = 0;
}
I get an error on the next to the third line from the bottom: shippingLocation.options[0] = swap;
The error states that "object doesn't support this property or method".
What's IE's beef with switching option items?