Position of an item in a select box

Hi sitepointers ,

is there a way to know the position of a specific item (selected) in a select list ?

any easy way to add the “move up , move down” in a select input ?

Do you mean you want to add Up/Down controls for a <select>?

<form>
<select name = "sb">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
<option value="6">Option 6</option>
</select><br>
<input type='button' value='Dn' onclick='sb.selectedIndex = Math.min( sb.selectedIndex + 1, sb.length - 1)'>
<input type='button' value='Up' onclick='sb.selectedIndex = Math.max( sb.selectedIndex - 1, 0 )'>
</form>

This particular syntax can only be used within the form.

Thank You bro , i will try it .

i came up with this solution in mootools :


    $('moveUp').addEvent('click', function() {
        $('service_id_2').getSelected().each(function(el) {
            var prev = el.getPrevious();
            if(prev && prev != null) {
            el.inject(prev,'before');
           }
        });
    });
    
    $('moveDown').addEvent('click', function() {
        $('service_id_2').getSelected().each(function(el) {
            var next = el.getNext();
            if(next && next != null) {
            el.inject(next,'after');
           }
        });
    });


That way you can move multiple items at the same time .

I see now it’s not what you wanted, but then you did ask very ambiguous question.