Aarthi Ravendiran
Aarthi Ravendiran

Reputation: 113

get the value of the dropdown of the particular row in a table using jquery

here is my html code

<td style="display:none">
    <div class="col-sm-6">
        <select class="form-control" id="riexclusion">
            <option value="yes">Yes</option>
            <option value="no">No</option>
        </select>
    </div>
</td>

i want to get the selected value from the dropdown list of every row.

I tried this jquery to retrieve the value..

var selectedstatus = $('#riexclusion option:selected').text();
alert(selectedstatus);
var totalrow = $("#ritable > tbody > tr").length;
for (var i = 0; i <= totalrow; i++) {
    exclusion = $('tbody#riDecisionvalues tr:eq(' + i + ')td:eq(8)').select();
}

help me with this...

add jsfiddle

Upvotes: 3

Views: 6507

Answers (4)

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

First of all you need to remove duplicate ids instead you can use class as shown below -

<td style="display:none">
    <div class="col-sm-6">
        <select class="form-control" class="riexclusion">
            <option value="yes">Yes</option>
            <option value="no">No</option>
        </select>
    </div>
</td>

Use below jQuery to get each selected value from dropdown

//iterate all select under each tr
$("#ritable  tbody  tr").find(".riexclusion").each(function(){
   selectedVal = $(this).val();
   alert(selectedVal);
});

Upvotes: 1

Ashish Bhagat
Ashish Bhagat

Reputation: 420

Try this code:

$("#ritable tbody tr:nth-child(8)")..find('select').val();

or if you want to loop through

var selectedstatus = $('#riexclusion').val();
$('tbody#riDecisionvalues tr').each(function(){
    $(this).find('td').eq(8).find('select').val(selectedstatus)
})

Upvotes: 0

stanze
stanze

Reputation: 2480

Try this fiddle

$('#riexclusion').on('change', function() {
    alert($(this).val());
})

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388326

Id of an element must be unique, so use as a riexclusion class(<select class="form-control riexclusion">), then you can use .map() to get an array of all the selected values

var exclusions = $('.riexclusion').map(function () {
    return this.value
}).get();

Upvotes: 0

Related Questions