Can anyone work out why this does not work. Produces NAN and if reset for a Number(document on var inputs produces 0. The script is supposed to add up an indefinite number of fields starting with an ID of product_total_price_PRI_ … .
Obviously I’ve missed something and have got a headache from trying to see it.
function getFields() {
var inputs = document.getElementsByTagName('input');
var result = 0;
for( var i = 0; i < inputs.length; i++ ) {
if( inputs[i].id.indexOf('product_total_price_PRI_') == 0 );
result += parseFloat(inputs[i].value);
}
alert(result);
}
Your
if()syntax is off, there’s a;ending the statement so yourresult +=is always running, it should be: