User-173651909 posted
Can someone help me find out why this function is completing? Here's the code:
function countTotals(myvalue)
{
var sumA = 0;
var sumB = 0;
var maxA = @ViewBag.MaxA;
var maxB = @ViewBag.MaxB;
var itemA = 0;
var itemB = 0;
var values;
$('.' + myvalue).each(function () {
if($(this).is(':checked')){
// split string and check weight and power
values = ($(this).val()).split("/");
itemA = parseFloat(values[0]);
itemB = parseFloat(values[1]);
// increment sum
sumA += itemA;
sumB = itemB;
}
});
alert('sumA: ' + sumA + ', maxA: ' + maxA);
if (sumA > maxA) {
alert('in if statement');
}
}
The function is called by a radiobutton onclick passing a value. The value passed can be 1 to 6 and is a classed use to group the radiobuttons. The function looks at each radiobutton in the group and if one is checked then it splits the string and assigns
the respective values to itemA and itemB. It then uses those values to increment a total (sumA and sumB).
The code works until I get to the if statement at the bottom which checks if the sum is greater than the max. The alert before the if statement executes successfully but it doesn't get further even if I say if (288 > 4). Any ideas why this might be?
Thanks in advance
Adam