It is really difficult to understand the context here. Do you have dependent dropdowns? Are you attempting to populate one or two select elements?
Mar 3, 2021
5
Level 4
jquery foreach loop with two array
Hello , How can I loop two array in one foreach loop
//List for select
TomList = ["A","B"],
BobList = ["C", "D"],
//
ListA = ["Tom","Bob"],
ListB = ["TomList","BobList"],
///////////////
// ////// I try these two loops, but I think this is wrong
/////////
$.each(ListA, function(indexA, valueA) {
$.each(ListB, function(indexB, valueB) {
if(selectedVal == "' + valueA + '") {
$.each(valueB, function(index, value) {
_options += '<option value="' + value + '" >' + value + '</option>';
});
});
});
}
it must loop like
if(selectedVal == "Tom") {
$.each(TomList, function(index, value) {
_options += '<option value="' + value + '" >' + value + '</option>';
});
if(selectedVal == "Bob") {
$.each(BobList, function(index, value) {
_options += '<option value="' + value + '" >' + value + '</option>';
});
Please or to participate in this conversation.