First iteration through the loop sets selected=true for every option, since they all match val(''). Firefox responds by selecting the first element only; IE selects the last. Subsequent iterations work fine since val(x) uses a unique value each time.