Loop is not initiating in this code and also split_value doesn't store any value. I want to compare dropdown value and excel data and then matched value should store in sum = [].
if (items) {
switch (currentControl) {
case "Record_Code":
var dropdownvalue1 = $.map($('#ddlOrderSourceEligibilityGoaloption'), function(ele) {
return {
text: ele.text,
value: ele.value
}
for (var v = 0; v < myitem.length; v++) {
isFound = 0;
for (i = 0; i < dropdownvalue1.length; i++) {
var split_value = dropdownvalue1[i].text.split('-');
if ((myitem[v].split('-')[0]).trim() == (split_value[0]).trim()) {
sum.push(dropdownvalue1[i].value);
isFound = 1;
break;
}
}
if (isFound == 0) {
NotFound.push(myitem[v]);
}
}
if (sum.length > 0) {
setMultiSelectValue("#ddlOrderSourceEligibilityGoal", sum);
$(".uploadExcelTE").val('');
}
});
break;
case "Order_Source":
break;
case "Order_Type":
break;
case "Bill_To_Cust":
break;
case "Item_Status":
break;
}
}
The problem is that you use a return statement in the first block of the switch-case statement. If currentControl is "Record_Code", the program always assigns dropdownvalue1 the value {text: ele.text, value: ele.value}.
if (items)
{
switch (currentControl)
{
case "Record_Code":
var dropdownvalue1 = $.map($('#element'), function (ele) {
// The dropdownvalue1 variable is always assigned the following result.
return { text: ele.text, value: ele.value }
// The code blocks below never work.
for(var v = 0; v < myitem.length ; v++){}
});
break;
}
}