SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 ?

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tekfirm View Post
    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>?
    Code:
    <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.
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank You bro , i will try it .

    i came up with this solution in mootools :


    Code JavaScript:
        $('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 .

  4. #4
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tekfirm View Post
    Thank You bro , i will try it .
    I see now it's not what you wanted, but then you did ask very ambiguous question.
    Tab-indentation is a crime against humanity.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •