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 8778765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:36:35+00:00 2026-06-13T19:36:35+00:00

Okay, I have this code: <select name=selector id=selector> <option value=1>Option 1</option> <option value=2>Option 2</option>

  • 0

Okay, I have this code:

<select name="selector" id="selector">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>

And I’d like to get the value of the option selected.
Example:
‘Option 2’ is selected, and the value of it is ‘2’. The ‘2’ is the value I need to get and not ‘Option 2’.

  • 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-13T19:36:36+00:00Added an answer on June 13, 2026 at 7:36 pm

    04/2020: Corrected old answer

    Use :selected pseudo selector on the selected options and then use the .val function to get the value of the option.

    $('select[name=selector] option').filter(':selected').val()
    

    Side note: Using filter is better then using :selected selector directly in the first query.

    If inside a change handler, you could use simply this.value to get the selected option value. See demo for more options.

    //ways to retrieve selected option and text outside handler
    console.log('Selected option value ' + $('select option').filter(':selected').val()); 
    console.log('Selected option value ' + $('select option').filter(':selected').text());
    
    $('select').on('change', function () {
      //ways to retrieve selected option and text outside handler
      console.log('Changed option value ' + this.value);
      console.log('Changed option text ' + $(this).find('option').filter(':selected').text());
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <select>
      <option value="1" selected>1 - Text</option>
      <option value="2">2 - Text</option>
      <option value="3">3 - Text</option>
      <option value="4">4 - Text</option>
    </select>

    Old answer:

    Edit: As many pointed out, this does not returns the selected option value.

    ~~Use .val to get the value of the selected option. See below,

    $('select[name=selector]').val()~~
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so i have this code: if (isset($_GET['book'])) { $query= SELECT book_id, title, authors.`author`
Okay I have something that looks like this: Company Name-1234 I only want the
Okay, I have this code: <script language=javascript type=text/javascript> <!-- function requestPage(page) { var request
Okay, so i have this code i wrote: class Connection { public static StreamWriter
Okay, right now I have a form that contains this select list: <%=Html.LabelFor(x =>
Okay. I have this code on my site: <?php session_start(); include database.php; include bruger.php;
Okay, I feel like I should be able to do this, but I have
Okay so I have this mode: class Posts(db.Model): rand1 = db.FloatProperty() #other models here
Okay, so I have this form that is set to preload a DB record
Okay, so I have this CSV file of products and all the products have

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.