user3704742
user3704742

Reputation: 13

Run the same function for all selects elements

I have a table that looks like this Table:

Table

For each select (when changed) I want to run a function that uses the values from that specific row

I have this but only works for the first select

$('#selectID').change(function(){
    var tr =$(this).closest('tr');
    var IDD = tr.find($('#selectID option:selected')).val();
);

Upvotes: 1

Views: 77

Answers (2)

anil singh butola
anil singh butola

Reputation: 119

id of button duplicate so it is not working best way set button class="selectID" then write this code

$('.selectID').change(function(){
var tr =$(this).closest('tr');
var IDD = tr.find($('#selectID option:selected')).val();
 );

Upvotes: 0

tymeJV
tymeJV

Reputation: 104775

Target all your selects, then use an instance of this to access the value:

$("select").change(function() {
    console.log(this.value);
});

Upvotes: 1

Related Questions