Again a small script that enables you to order items in a listbox or (html) optoin. Just include this script in your page:

function move(index,to,list) 
{
    var total = list.options.length-1;
    if (index == -1) return false;
    if (to == +1 && index == total) return false;
    if (to == -1 && index == 0) return false;
    var items = new Array;
    var values = new Array;
    for (i = total; i >= 0; i--) 
    {
        items[i] = list.options[i].text;
        values[i] = list.options[i].value;
    }
    for (i = total; i >= 0; i--) 
    {
        if (index == i) 
        {
            list.options[i + to] = new Option(items[i],values[i], 0, 1);
            list.options[i] = new Option(items[i + to], values[i + to]);
            i--;
        }
        else 
        {
            list.options[i] = new Option(items[i], values[i]);
        }
    }
    list.focus();
}

 

When you are using asp.Net you can set this script from the code behind like this:

btnUp.Attributes.Add("onclick", "move(" + lstOrder.ClientID + 
".selectedIndex, -1,"+lstOrder.ClientID+")");
btnDown.Attributes.Add("onclick", "move(" + lstOrder.ClientID + 
".selectedIndex,+1," + lstOrder.ClientID + ")");

 

You can now click on the up and down arrows to move an item in the list.

         

I had lots of help from this site: http://javascript.internet.com/forms/selection-order.html