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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:38:17+00:00 2026-06-01T04:38:17+00:00

Ultimately I am trying to run some code which depends on the value (or

  • 0

Ultimately I am trying to run some code which depends on the value (or data stored in any attribute, like rel, etc.) of a select‘s option, when that option gets selected. I have the following code:

JavaScript:

$('select#select1').change(function () {
  set = $('#select1 option:selected').val();
  alert(set);
  // $('#select2').html()
}); 

HTML:

<select id="select1">
  <option value="1" rel="1">First</option>
  <option value="2" rel="2">Second</option>
  <option value="3" rel="3">Third</option>
  <option value="4" rel="4" selected="selected">Fourth</option>
</select>

There are actually two problems here. Firstly, the code above does nothing, as the change function doesn’t seem to recognize the $('select#select1') selector on the first line. If I change it to just $('select'), it works. But this is no good, as there are several select elements on my page and I need to distinguish which one.

Secondly, if I get it working temporarily with $('select') (and deleting other select elements on the page) then I always get the value “1” being alerted, no matter which of the 4 options I select.

Same happens if I use $('#select1 option:selected').attr('rel'); instead.

For the love of God, why?

  • 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-01T04:38:19+00:00Added an answer on June 1, 2026 at 4:38 am

    Try wrapping it inside $(document).ready(function () {... }); and use $(this).val() inside your handler. See below,

    DEMO

    $(document).ready(function () {
        $('#select1').change(function () {
            alert($(this).val());
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using Visual.Web.Developer.2010.Express; using SQL.Server.Management.Studio.2008.R2; What I'm ultimately trying to do is update a sql
Ultimately I'm trying to write out a range into a text file. When I
I am trying to use FileHelper library for parsing a text file. Ultimately the
Background Information: Ultimately, I would like to write an emulator of a real machine
I'm setting up a website which ultimately displays videos. The video files are all
I'm currently designing an application which I will ultimately want to move to Windows
I have two arrays that I would like to compare and ultimately wind up
I am currently trying to listen for when the power button is pressed. Ultimately
I am trying to convert my model-first project to code-first, as I can see
I'm having trouble getting a custom config section to work. It's some code I

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.