I am trying to get the total value from an array of form fields but for some reason the value is incorrect on Keyup the final value gets added from the last inputed value and not all of the fields here is my function:
function percentage_hardcoded_form(_formharcoded_id, _form_fieldArray, _form_hardcodedtotalWrapper, _form_hardcodedtotalId) {
var _form = $j(_formharcoded_id);
var _sumDisplay = _form.find(_form_hardcodedtotalId);
$j(_form_hardcodedtotalId).attr('disabled','disabled');
$j.each(_form_fieldArray, function(index, item) {
var _summands = item;
var sum = 0;
_form.delegate(_summands, 'change', function () {
//$j.each(function () {
var value = Number($j(this).val());
if (!isNaN(value) && !$j(this).is(_form_hardcodedtotalId)) sum += value;
//});
if(sum === 100)
{
// is 100
$j(_form_hardcodedtotalWrapper).removeClass('warning');
$j(_form_hardcodedtotalWrapper).find('.QuestionWarning').hide();
}
else
{
// isnt 100
$j(_form_hardcodedtotalWrapper).addClass('warning');
$j(_form_hardcodedtotalWrapper).find('.QuestionWarning').show();
}
_sumDisplay.val(sum);
});
});
}
percentage_hardcoded_form('#aspnetForm #questions_page_Page17', designForm_ids_1, "#question_DCWorkSplit", "#DCWorkSplit");
Here is a jsfiddle of what I am working with: http://jsfiddle.net/q05k48b7/1/
Update
I have updated the JS fiddle see link below, still not working.
sumalways resets to 0 on everyonblurevent.onchangeevent happens