1

I want to override the general behavior of an HTML select element by making it fire the change event even when the selected option hasn't changed.

$('select').change(function() {
  alert($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>

How can i achieve this?

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
pavan kumar
  • 408
  • 5
  • 19

1 Answers1

2

You can try like this:-

HTML :

<select>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
</select> 

JS :

$("select").mouseup(function() {
    var flag = $(this).data("flag");
        var cur_val = $(this).val();
    if(flag) {
        alert(cur_val);
    }
    $(this).data("flag", !flag);
});

Here is working jsfiddle.

Give it a try, this should work.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Rahul
  • 18,271
  • 7
  • 41
  • 60