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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:57:45+00:00 2026-05-11T03:57:45+00:00

I have a select control, and in a javascript variable I have a text

  • 0

I have a select control, and in a javascript variable I have a text string.

Using jQuery I want to set the selected element of the select control to be the item with the text description I have (as opposed to the value, which I don’t have).

I know setting it by value is pretty trivial. e.g.

$('#my-select').val(myVal); 

But I’m a bit stumped on doing it via the text description. I guess there must be a way of getting the value out from the text description, but my brain is too Friday afternoon-ed to be able to work it out.

  • 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. 2026-05-11T03:57:45+00:00Added an answer on May 11, 2026 at 3:57 am

    Select by description for jQuery v1.6+

    var text1 = 'Two'; $('select option').filter(function() {   //may want to use $.trim in here   return $(this).text() == text1; }).prop('selected', true);
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>  <select>   <option value='0'>One</option>   <option value='1'>Two</option> </select>

    jQuery versions below 1.6 and greater than or equal to 1.4

    var text1 = 'Two'; $('select option').filter(function() {   //may want to use $.trim in here   return $(this).text() == text1; }).attr('selected', true);
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/1.4.0/jquery.min.js'></script>  <select>   <option value='0'>One</option>   <option value='1'>Two</option> </select>

    Note that while this approach will work in versions that are above 1.6 but less than 1.9, it has been deprecated since 1.6. It will not work in jQuery 1.9+.


    Previous versions

    val() should handle both cases.

    $('select').val('1'); // selects 'Two' $('select').val('Two'); // also selects 'Two'
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/1.2.3/jquery.min.js'></script>  <select>   <option value='0'>One</option>   <option value='1'>Two</option> </select>

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

Sidebar

Ask A Question

Stats

  • Questions 167k
  • Answers 167k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The test current_part.to_s == "" returns true on my ruby… May 12, 2026 at 1:26 pm
  • Editorial Team
    Editorial Team added an answer Try: /^([0-9]{1,2}\-\[0-9]{1,2}\-\[0-9]{4})?$/ It will then match when a valid date… May 12, 2026 at 1:26 pm
  • Editorial Team
    Editorial Team added an answer I have done this recently in Java: public static final… May 12, 2026 at 1:26 pm

Related Questions

I have an XML feed (which I don't control) and I am trying to
IE 8 is not refreshing a popup window that shows an image with some
I have a UserControl that I want to include in a page multiple times
I'm using the Textpattern CMS to build a discussion site-- I have a firm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.