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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:20:55+00:00 2026-05-12T17:20:55+00:00

I have a ‘select’ drop-down with a list of players’ names, which by default

  • 0

I have a ‘select’ drop-down with a list of players’ names, which by default has the first item–also an empty item, selected. I would like to do a simple test on whether this item is selected when the user clicks a button below.

I came across two possible solutions:

1)

if( $("#players option:selected").is(":eq(0)") )
{
    alert("Please select a player!");
}

and

2)

if( $("#players option:eq(0)").is(":selected") )
{ 
    alert("Please select a player!");
}

Solution #2 works perfectly, but #1 always returns true. Does anyone know of a technical reason or limitation on why this is?

Thanks for your replies!

  • 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-12T17:20:55+00:00Added an answer on May 12, 2026 at 5:20 pm

    To answer why number 1 is always true, it’s because 1 and 2 do slightly different things.

    Solution #1 says “get me the selected <option> and then check if it’s in the first position in the wrapped set”, which it always will be (you can have only one selected option at a time).

    Solution #2 says “get me the first <option> and then tell me if it’s selected”, which it won’t be if any other <option> other than the first is selected.

    EDIT:

    I think what you’re looking for in Solution #1 is the following

    if( $("#players option:selected").is(":first-child") )
    {
        alert("Please select a player!");
    }
    

    Here’s a Working Demo of that in action. add /edit to the URL to see the code

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

Sidebar

Related Questions

Have a simple one-off tasks which needs a progress bar. OpenSSL has a useful
Have I understod the following right? font-family:sans-serif; Above will result in the default sans-serif
Have just started using Visual Studio Professional's built-in unit testing features, which as I
**Have it working now. I forgot to populate the Array List. How embarrassing. I'm
Have a group of related projects running in SQL Server 2005 for which I
Have anyone used Redmine Documentor which lets you convert PHP to HTML to Redmine
Have the following scenario. I have a few form, which essentially have a few
I have a text area in my form which accepts all possible characters from
Have an app that can use tts to read text messages. It can also
Have a bunch of classes which I need to do serialize and deserialize from/to

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.