Forum Moderators: open
<select> list to another, keeping the item selected when it hits the other list, and then sorting the list. All is fine except in NN6.2.2 I lose my option's selected status, and it is happening right before the sort function. In order to sort, I'm moving the select.option array into a new Array() and it's at that point that the value is returning false. Here is a small piece of the javascript for reference:
if (to.name == 'list1') {
sort_list = new Array();
for (var i = 0; i < to.options.length; i++) {
sort_list[i] = new Option(to.options[i].text, to.options[i].value, to.options[i].defaultSelected, to.options[i].selected)
alert('Before: ' + to.options[i].text + "/" + to.options[i].selected + "\nAfter: " + sort_list[i].text + "/" + sort_list[i].selected)
}
.
.
.
[edited by: tedster at 11:51 pm (utc) on Aug. 22, 2003]
[edit reason] reduce side scroll [/edit]
if (to.name == 'list1') {
sort_list = new Array(); for (var i = 0; i < to.options.length; i++) {
sort_list[i] = new Option(to.options[i].text, to.options[i].value, to.options[i].defaultSelected, to.options[i].selected);
alert('Before: ' + to.options[i].text + "/" + to.options[i].selected + "\nAfter: " + sort_list[i].text + "/" + sort_list[i].selected);
}
}
========
Ps. If it is the constructor that is the issue, you could just do...
sort_list[i] = new Option();
sort_list[i].text = to.options[i].text;
sort_list[i].value = to.options[i].value;
sort_list[i].defaultSelected = to.options[i].defaultSelected;
sort_list[i].selected = to.options[i].selected;
Jordan
var select_list = new Array();
if (to.name == 'list1') {
sort_list = new Array();
for (var i = 0; i < to.options.length; i++) {
sort_list[i] = new Option(to.options[i].text,
to.options[i].value,
to.options[i].defaultSelected,
to.options[i].selected);
select_list[i] = to.options[i].selected;
alert('Before: ' + to.options[i].text + "/" +
to.options[i].selected + "\nAfter: " +
sort_list[i].text + "/" +
sort_list[i].selected);
}
}
...then after you insert the new list (assuming for the example that it has the id "list"), run through another loop...
var sl = document.getElementById("list");
for (var i = 0; i < sl.options.length; ++i) {
sl.options[i].selected = select_list[i];
}
HTH
Jordan
...then after you insert the new list (assuming for the example that it has the id "list"), run through another loop...Yeah, tried this, too. It won't work as the array has been sorted and no longer has the same sequence at this point. I think it has something to do with the way that NN6 handles a new Array() versus new Option() and/or how I'm attempting to use them that way. All the support I find describes sorting arrays using this technique, including devedge.netscape.com. I was just hoping to find some conclusive evidence that I've really got my code wrong rather than discovering a bug (that has apparently been fixed, since NN7 processes just fine). I'm just concerned about backward compatibility. If I could employ a viable NN6 workaround, I'd be happy.
Jordan