Rob,

>Thanks for that - I'm having trouble transferring the technique behind it
>though.
>Debugging with Firebug and putting breakpoints in _Field_transferTo() and
>_transferOptions() then double-clicking or using the buttons to transfer
>never breaks...
>
>I've looked through the source for those functions anyway and instead of
>using select.selectedIndex I tried checking option.selected for each option
>element - I still have the same problem that the function is executed
>_before_ the attributes are changed in IE6. The example page that you
>pointed me to works fine though.

I think I know what might be happening. IE may not be updating the DOM
element until after the event--which would explain why in jQuery you're not
able to get the elements via a CSS selector.

My example code actually using DOM methods to loop through the option
array--which is more efficient anyway. 

So, what it should like you'll need to do is loop through the option
elements and check the selected property for each item.

Something like this:

<select id="transferFrom" />
<select id="transferTo" />

// set the onchange event
$("#transferFrom").bind(
        "onchange", 
        function(){
                moveOption(this, $("#transferTo")[0]);
        }
);

// oFrom is a reference to the select element moving items from
// sTo is a reference to the select element we're moving item to
function moveOption(oFrom, oTo){
        var iLen = oFrom.length;
        for( var i=0; i < iLen; i++ ){
                if( oForm.options[i].selected ){
                        // move item
                        oTo.options[oTo.length] = new Option(
                                oForm.options[i].text,
                                oForm.options[i].value
                        );
                        // remove item
                        oFrom.options[i] = null;
                        // since you just deleted a option, redo this array
                        //position next loop
                        i--; 
                }
        }
}

I did not test the code, but I think it should work. It's at least pretty
close.

-Dan

Reply via email to