SELECT drop down list - SKIP

Discussion in 'Javascript' started by magix, Mar 19, 2007.

  1. magix

    magix Guest

    I have an drop down list

    let say:

    <SELECT name="id" id="id" OnClick="Skip()">
    <option value="0"></option>
    <option value="1">Item 1</option>
    <option value="2">Item 2</option>
    <option value="3">Item 3</option>
    <option value="4">Item 4</option>
    </SELECT>




    I have a skip button (with the OnClick javascript function, whenever I click
    skip, the drop down list will select the next Item of the current one.

    Example:
    - the current selected item is Item 2, when click Skip, it will select Item
    3
    - the current selected item is Item 3, when click Skip, it will select Item
    4
    - the current selected item is Item 4, when click Skip, it will select the
    first one, which is Value 0

    like a circle...

    how to do that in javascript ?
    <Script language="javascript">

    function skip()
    {

    }
    </script>

    thanks.
     
    magix, Mar 19, 2007
    #1
    1. Advertising

  2. magix

    Guest

    On Mar 19, 12:54 pm, "magix" <> wrote:
    > I have an drop down list


    > I have a skip button (with the OnClick javascript function, whenever I click
    > skip, the drop down list will select the next Item of the current one.



    great. what is the question ?

    like a circle...
    >
    > how to do that in javascript ?


    if you already have the function then why you are asking.

    html-
    <SELECT id="idSel">
    <option value="0">Item 0</option>
    <option value="1">Item 1</option>
    <option value="2">Item 2</option>
    <option value="3">Item 3</option>
    <option value="4">Item 4</option>
    </SELECT><br>
    <button onclick="Next()"> Select Next </button>

    JavaScript-
    function Next(){
    var SelEct=document.getElementById("idSel")
    var Curr=SelEct.selectedIndex
    SelEct.selectedIndex=(Curr<(SelEct.options.length-1))?++Curr:0
    }
     
    , Mar 19, 2007
    #2
    1. Advertising

  3. magix

    RobG Guest

    On Mar 20, 5:27 am, wrote:
    > On Mar 19, 12:54 pm, "magix" <> wrote:
    >
    > > I have an drop down list
    > > I have a skip button (with the OnClick javascript function, whenever I click
    > > skip, the drop down list will select the next Item of the current one.

    [...]
    > > how to do that in javascript ?

    [...]
    >
    > JavaScript-
    > function Next(){
    > var SelEct=document.getElementById("idSel")
    > var Curr=SelEct.selectedIndex
    > SelEct.selectedIndex=(Curr<(SelEct.options.length-1))?++Curr:0
    >
    > }


    How about:

    function nextOption(sel) {
    var idx = sel.selectedIndex;
    sel.selectedIndex = ++idx % sel.options.length;
    }


    --
    Rob
     
    RobG, Mar 19, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SirPoonga
    Replies:
    2
    Views:
    771
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,023
    weiwei
    Jan 5, 2007
  3. msimmons
    Replies:
    0
    Views:
    487
    msimmons
    Jul 16, 2009
  4. Replies:
    5
    Views:
    274
  5. Replies:
    3
    Views:
    291
Loading...

Share This Page