0

I have a dropdown select form element. When an option is selected, I want to do something. Even if the value that is chosen from the dropdown is the already-selected option. So "on change" won't work in this case.

How can I do that?

bevanb
  • 8,201
  • 10
  • 53
  • 90

1 Answers1

0

Since your option is "actually" not changing, jQuery change event won't fire automatically. Instead you need to bind it. Use the click event as suggested by @epoch:-

Sample Code:-

             //Intialize a local variable
             var x = 0;
             $('#single').click(function () {
                 //Increment local variable by 1.
                 x = x + 1;
                 //Since click event will be fired twice (once during focus & second while   selecting the option) compare '2' for same selection
                 if (x == 2) {
                     $(this).change();
                     x = 0;
                 }
             }).change(function () {
                 console.log(1);
                 //To reset the value of x back to 0, set it as -1 here (since click event will be fired after change).
                 x = -1;
             });
Rahul Singh
  • 21,585
  • 6
  • 41
  • 56