LAwebTek
02-05-2003, 10:08 PM
The following code works fine for removing options from a select list, except that if I remove the last option in the list I want the option that becomes the new-last option (options.length) to become selected. Any ideas?
function remove() {
playList = document.amp.playlist.options;
for(var i=0; i<playList.length; i++) {
if(playList[i].selected && playList[i] != "") {
playList[i].value = "";
playList[i].text = "";
}
}
BumpUp();
}
function BumpUp() {
for(var i = 0; i < playList.length; i++) {
if(playList[i].value == "") {
for(var j = i; j < playList.length - 1; j++) {
playList[j].value = playList[j + 1].value;
playList[j].text = playList[j + 1].text;
}
var ln = i;
break;
}
}
if(ln < playList.length) {
playList.length -= 1;
}
}
function remove() {
playList = document.amp.playlist.options;
for(var i=0; i<playList.length; i++) {
if(playList[i].selected && playList[i] != "") {
playList[i].value = "";
playList[i].text = "";
}
}
BumpUp();
}
function BumpUp() {
for(var i = 0; i < playList.length; i++) {
if(playList[i].value == "") {
for(var j = i; j < playList.length - 1; j++) {
playList[j].value = playList[j + 1].value;
playList[j].text = playList[j + 1].text;
}
var ln = i;
break;
}
}
if(ln < playList.length) {
playList.length -= 1;
}
}