Refactoring my old DualSelectBox [1], I thought it would be much smarter
to get rid of the new Option() stuff, and instead just switch childNodes
between the two select elements. Something like that:
function shiftSelectedOp tions(src, dest) {
var i, len, opts = [];
for(i = 0, len = src.options.len gth; i < len; i++) {
if (src.options[i].selected) {
opts.push(src.o ptions[i]);
}
}
for(i = 0, len = opts.length; i < len; i++) {
opts[i].selected = false;
dest.appendChil d(opts[i]);
}
}
Works as expected in all reasonable browsers, alas IE6 (and perhaps 7,
too) has issues. The childNodes get removed from the source element, and
get appended to the destination element - at least that's what this
abysmal DOM Explorer tells me. But they stay invisible - as if some sort
of "refresh" is missing.
To add to the confusion: The above function gets called upon
initialization of the widget, and there it works (i.e. the options show
up), despite nothing explicit happens to the DOM after calling above
function. Just subsequent adding fails.
init() {
....
sourceBox = destinationBox. cloneNode(false );
destinationBox. parentNode.inse rtBefore(source Box, destinationBox) ;
shiftSelectedOp tions(destinati onBox, sourceBox);
window.alert("c heck!"); // options visible
}
BTW: The childNodes of the select elements get cleaned, i.e. all nodes
that are not of the "OPTION" type get removed, including plain textnodes.
Any idea, how to deal with this issue?
Gregor
[1]
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
to get rid of the new Option() stuff, and instead just switch childNodes
between the two select elements. Something like that:
function shiftSelectedOp tions(src, dest) {
var i, len, opts = [];
for(i = 0, len = src.options.len gth; i < len; i++) {
if (src.options[i].selected) {
opts.push(src.o ptions[i]);
}
}
for(i = 0, len = opts.length; i < len; i++) {
opts[i].selected = false;
dest.appendChil d(opts[i]);
}
}
Works as expected in all reasonable browsers, alas IE6 (and perhaps 7,
too) has issues. The childNodes get removed from the source element, and
get appended to the destination element - at least that's what this
abysmal DOM Explorer tells me. But they stay invisible - as if some sort
of "refresh" is missing.
To add to the confusion: The above function gets called upon
initialization of the widget, and there it works (i.e. the options show
up), despite nothing explicit happens to the DOM after calling above
function. Just subsequent adding fails.
init() {
....
sourceBox = destinationBox. cloneNode(false );
destinationBox. parentNode.inse rtBefore(source Box, destinationBox) ;
shiftSelectedOp tions(destinati onBox, sourceBox);
window.alert("c heck!"); // options visible
}
BTW: The childNodes of the select elements get cleaned, i.e. all nodes
that are not of the "OPTION" type get removed, including plain textnodes.
Any idea, how to deal with this issue?
Gregor
[1]
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Comment