Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9244677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:05:40+00:00 2026-06-18T09:05:40+00:00

I have a <select> , and on button click users can select the next

  • 0

I have a <select>, and on button click users can select the next option:

$(".someButton").on('click', function () {
   var $opt = $("select :selected");

   $("select").val($opt.next().val());
});

The problem is that on the last option, $opt.next().val() returns some unselectable value, and apparently jQuery selects the first option by default. What I would like is for it to stay on the last option.

Is there any way to do this (preferably without checking the position of $opt or the length of $opt.next())?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:05:42+00:00Added an answer on June 18, 2026 at 9:05 am

    Here’s a more efficient way to do it:

    $(".someButton").on('click', function () {
       var el = $("select")[0];
       el.selectedIndex = Math.min(el.selectedIndex + 1, el.length - 1);
    });
    

    If you want to stick to jQuery, set the option to selected:

    $opt.next().prop('selected', true);
    

    If $opt is the last one, .next() will return an empty set, so nothing will change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button, on click of which i display a multi-select dialog. I
I have two forms, one with a radio button that users must select to
I have code below: <select id=testSelect> <option value=1>One</option> <option value=2>Two</option> </select> <asp:Button ID=btnTest runat=server
I have a select element from which the users can select a value and
I have an option in my application where users can deactivate their profiles. Only
I have a multi-select <asp:listbox> and a button. I want to disable the button
OK, I have two HTML select elements and a button. I need to disable
I have... a dynamic populated select box several input boxes a submit button form
I have a MySQL query that goes as follows SELECT count(`clicks`.`user_id`) as total, `users`.`fullname`
I have a site where I would like to let users select multiple images

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.