I have an array called billItems in my jquery, and am having values in that like,
[TUTION FEE ,SPORTS FEE ,CONVOCATION FEE ]
am iterating the billItems before adding new item, to avoid duplicate, like
for (var i = 0; i < billItems.length; i++) {
var name = billItems[i];
if (name == feesItem.ItemName) { //here ItemName=TUTION FEE
var validItem = 'False'
}
}
as I mentioned above, am passing the ItemName as TUTION FEE, but its not comparing the strings and the control not comes into the block even its same. whats wrong with this query, can anyone help me here….
am just appending the datas into a html table like
var feesItem = new Object();
feesItem.ItemName = $("#txtItemName").val();
feesItem.Amount = $("#txtAmount").val();
$("#BillTable > tbody").find("tr:gt(0)").remove();
for (var i = 0; i < feesItemList.length; i++) {
tab = "<tr><td>" + " <span class='bid'>" + feesItem[i].ItemName + " </span>
</td><td>" + feesItem[i].Amount + "</td></tr>";
$("#BillTable > tbody").append(tab);
}
its still not comparing the values…
I just tried comparing the values within the for loop like,
var billItems = [];
$(".bid").each(function () {
billItems.push($(this).text());
});
var validItem = ($.inArray(feesItem[i].ItemName, billItems) < 0);
I’m going to go on a limb here and guess that your strings are not exactly what they seem. Try changing the comparison to:
This will remove any trailing or leading spaces from both arguments before comparison. Hope that helps.