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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:06:20+00:00 2026-06-03T07:06:20+00:00

How (using Javascript or jQuery) can I detect when a value has been selected

  • 0

How (using Javascript or jQuery) can I detect when a value has been selected from a select box, even if it’s the same option as was previously selected (i.e. no change event is fired).

Mainly I need this for mouse interaction, but a solution that works for keyboard too would be handy.

  • 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-03T07:06:21+00:00Added an answer on June 3, 2026 at 7:06 am

    The only solution I found workable is to cause change event by setting the value of select to some other on mousedown. In the markup I created one extra option (i.e. the first child) and made it hidden (hides perfectly in Chrome/FF/Safari, IE as usual). So it looks fine.

    <select>
        <option style="display: none"></option>
        <option>First</option>
        <option>Second</option>
        <option>Third</option>
    </select>​
    

    Then using jQuery we bind change and mousedown events in a way that when mousedown triggers, select resets its value to the value of the hidden option.

    $("select").on({
        change: function() {
            console.log($(this).val());
        },
        mousedown: function() {
            $(this).val($(":first", this).val());
        }
    });​
    

    DEMO: http://jsfiddle.net/LzNrS/

    UPDATE: In order to preserve the selected value when user has clicked on select but decided not the choose anything, we can modify the code a bit adding blur event and updating mousedown.

    var special = ""; // special hidden option value
    var value = ""; // temporary variable
    
    $("select").on({
        change: function() {
            console.log($(this).val());
        },
        mousedown: function() {
            if (this.value == special) {
                $(this).val(value);
                return;
            }
            value = this.value;
            $(this).val(special);
        },
        blur: function() {
            if (this.value == special)
                $(this).val(value);
        }
    });​
    

    DEMO: http://jsfiddle.net/LzNrS/1/

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

Sidebar

Related Questions

How can you copy text to clipboard using Javascript (or even nicer a jQuery
How can I change CSS from javascript . I'm using jQuery-ui Dialog and I
I'm using JavaScript/Jquery to make a page auto-update with a value from a database,
In javascript, possibly using jQuery, how can I detect if the html content of
In Javascript/jQuery, how can I detect if the client device has a mouse? I've
I'm trying to make a drop down menu using javascript/jquery but can't get my
How can I manipulate using JavaScript (JQuery) a site, not in my server, that
How can I simulate a click at x/y co-ordinates using javascript or jquery? I
I was creating a countdown timer using javascript; I can use jQuery. I want
In a htmlpage using jQuery or JavaScript how can the following be achieved? User

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.