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

  • SEARCH
  • Home
  • 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 6081513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:11:02+00:00 2026-05-23T11:11:02+00:00

Is it possible with jQuery to get the value of a select box item

  • 0

Is it possible with jQuery to get the value of a select box item based on the selected index? I ask because what I actually need is the value of the items before and after the current selectedindex for next/previous buttons. This is the code I tried but it did not work.

var my_value = $('#my_element_id').attr("selectedIndex").val();
  • 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-05-23T11:11:03+00:00Added an answer on May 23, 2026 at 11:11 am

    This should do it (after my 3rd edit 🙂 )

    It’s quite verbose, but pretty easy to see what it’s doing. I’m sure you can shorten it:

    Here is a working example: http://jsfiddle.net/59SPw/

    html:

    <select id="my_element_id">
        <option>Alex</option>    
        <option selected="selected">IS</option>
        <option>Cool</option>
    </select>
    

    Js:

    var selectedIndex = $('#my_element_id :selected').index();
    
    if(selectedIndex  > -1)
    {
        selectedIndex = selectedIndex + 1; //index() is 0 based, nth-child is 1 based
    
        var prevIndex = selectedIndex - 1;
        var nextIndex = selectedIndex + 1;
    
        var prev = $('#my_element_id :nth-child(' + prevIndex  + ')').val();
    
        var next= $('#my_element_id :nth-child('+  nextIndex + ')').val();
    
        alert(prev || "no previous");
        alert(next || "no next");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to get a particular value out of viewstate using JQuery.... I'm
Possible Duplicate: jQuery get input value after keypress I'm trying to get an input
Is it possible to get the value of the handle of a jQuery UI
Possible Duplicate: How do I get the value of a textbox using jQuery? on
I was wondering if it’s possible to get jQuery to select an <option> ,
Possible Duplicate: How to get all options of a select using Jquery? I have
Possible Duplicate: How to get the text of the selected option of a select
This is a really simple question. Is it possible for jQuery to get an
Possible Duplicate: How to get all of the IDs with jQuery? How can i
Is it possible to get all div's within a page using jQuery including nested

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.