views:

27

answers:

1

Hi guys,

I have two select boxes (available products and selected products). The use moves the items from one listbox to another. This works fine but in IE when i do a .remove(selectedIndex) (Javascript) on the option they selected the selectedIndex of that box gets set to -1. I want the listbox to remain in the same position but just remove the product they selected.

I have also tried

listbox.options[iProductIndex] = null;

This behaves the same.

Any help would be greatly appreciated.

Regards

Sam

A: 

Keep the old selectedIndex in a variable then change it back once the removal process is complete:

var oldSelectedIndex = obj.selectedIndex;
obj.remove(oldSelectedIndex);
obj.selectedIndex = oldSelectedIndex;

You should also make sure that oldSelectedIndex is not out of bounds after you remove one item, but the above snippet was to get the idea across.

David L.-Pratte
Same problem as above, the listbox is a multiselect and it doesnt guarantee they selected the top item, therfore the items above the one selected are pushed up and not visible by the user.
sam