another 'almost'

admin

Administrator
Staff member
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.selected && playList != "") {
playList.value = "";
playList.text = "";
}
}
BumpUp();
}

function BumpUp() {
for(var i = 0; i < playList.length; i++) {
if(playList.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;
}
}
 
Back
Top