
Untitled
By: a guest on Feb 4th, 2010 | syntax:
JavaScript | size: 1.06 KB | hits: 89 | expires: Never
// switch boxes
function moveSelectedOptions(from,to) {
// Unselect matching options, if required
if (arguments.length>3) {
var regex = arguments[3];
if (regex != "") {
unSelectMatchingOptions(from,regex);
}
}
// Move them over
for (var i=0; i<from.options.length; i++) {
var o = from.options[i];
if (o.selected) {
to.options[to.options.length] = new Option( o.text, o.value, false, false);
// var optGrps = to.getElementsByTagName("optgroup");
//optGrps.insertBefore(new Option( o.text, o.value, false, false) , this.firstChild);
// try {
// to.add(new Option( o.text, o.value, false, false),to.options[0]);
// }catch(ex) {
// to.add(new Option( o.text, o.value, false, false),0);
// }
}
}
// Delete them from original
for (var i=(from.options.length-1); i>=0; i--) {
var o = from.options[i];
if (o.selected) {
from.options[i] = null;
}
}
if ((arguments.length<3) || (arguments[2]==true)) {
//sortSelect(from);
//sortSelect(to);
}
from.selectedIndex = -1;
to.selectedIndex = -1;
}