pheromix
pheromix

Reputation: 19297

How to know with jQuery the last changed select element among two?

There are two select elements. Their default value is "" showing the text "Select a value". I want to know with jQuery which of them the user selected last in the case their values are both not "" ?

Upvotes: 0

Views: 59

Answers (1)

John Dvorak
John Dvorak

Reputation: 27287

You can track this manually:

<select id="s1" class="watched">
   ...
</select>
<select id="s2" class="watched">
   ...
</select>

...

var lastChanged = $();
$('select.watched').on('change'){
  lastChanged = $(this);
}

Note that it's not neccessary to set the class as long as you can identify the selects through other means (e.g. $('form#my-form select') or even $('select') if there are no other selects on the page).

Upvotes: 1

Related Questions