I am trying to figure out how to change the selection of multiple select boxes.
Here is what I currently have:
function selectStrategies() {
$('#dataTable tr').each(function() {
if($(this).find("td").eq(0).html()) {
$(this).find("td select").val($('#mainStrategyChoice').val());
}
});
}
I have a main drop-down box. When the selection of that box is changed, I call the selectStrategies function which suppose to adjust the selection for all rows in the table. The provide code above worked perfectly until I had to add second drop-down box for each row. I am trying to find a way to refer to first and second drop-down box.
Thank you.
Is there anything specific on those first and second select boxes? A class, an ID, or even a name could help, because you can target those (or part of those) with jQuery selectors. If there is nothing like that, for convenience you should add something common to the select
s you want to target.
For class="firstSelect"
:
$(this).find("td select.firstSelect").val($('#mainStrategyChoice').val());
If the name
is always sg like first-213
, first-84
, etc.:
$(this).find("td select[name^="first-"]").val($('#mainStrategyChoice').val());