Reputation: 181
I have a table with 10 columns
I am trying to loop through the NAME row to get the 4 selected names from the dropdowns.
I used to only need one, but had to add 3 more. I get one by this code
var $tds = $(this).find('td').filter(':visible')
name = $tds.eq(0).children().val()
I just can't work it out... GONE blank.
Any code or help would be appreciated.
Happy Holidays
Upvotes: 0
Views: 214
Reputation: 8868
You can iterate through each select
in the first td
cell using $.each()
. To get to the correct selector, you may use :first
instead of eq(0)
.
var arr = [];
$('td:visible:first select').each(function()
{
arr.push($(this).val());
});
Example : https://jsfiddle.net/DinoMyte/rv3wwpsf/1/
UPDATE : To find all select values in all rows :
var arr = [];
$('tr').each(function()
{
$(this).find('td:visible:first select').each(function(){
arr.push($(this).val());
});
});
alert(arr);
https://jsfiddle.net/DinoMyte/rv3wwpsf/2/
Upvotes: 1
Reputation: 12163
You should be able to use .map
var vals = $tds.eq(0).children('select').map(function() {
return $(this).val();
}).get();
Upvotes: 1