There's a more direct way of doing this...
Given a listbox with elements named mylistbox and two buttons named btnUp
and btnDown:
function btnUp_onclick() {
var StrStoreValue;
if ((mylistbox.selectedIndex == -1) || (mylistbox.selectedIndex == 0))
return;
strStoreValue = mylistbox.options[mylistbox.selectedIndex - 1].text;
mylistbox.options[mylistbox.selectedIndex - 1].text = mylistbox.options
[mylistbox.selectedIndex].text;
mylistbox.options[mylistbox.selectedIndex].text = strStoreValue;
mylistbox.selectedIndex = mylistbox.selectedIndex - 1;
}
function btnDown_onclick() {
var strStoreValue;
if ((mylistbox.selectedIndex == -1) || (mylistbox.selectedIndex ==
mylistbox.options.length - 1)) return;
strStoreValue = mylistbox.options[mylistbox.selectedIndex + 1].text;
mylistbox.options[mylistbox.selectedIndex + 1].text = mylistbox.options
[mylistbox.selectedIndex].text;
mylistbox.options[mylistbox.selectedIndex].text = strStoreValue;
mylistbox.selectedIndex = mylistbox.selectedIndex + 1;
}
Just call these functions on the onclick events of the Up and Down buttons
and you're all set =)