function doCalc(form) {
   var i = 0, qtot = 0, ptot = 0, q, cur;
   
   while (cur = form.elements['data[' + i + '][quantity]']) {
      q = getIntValue(form.elements['data[' + i + '][quantity]']);
      qtot += q;
      ptot += q * getIntValue(form.elements['data[' + i + '][price]']);
      i++;
   }
   
   form.elements['totalquantity'].value = qtot;
   form.elements['totalprice'].value = ptot;
}



function getIntValue(field) {
   var tmpval = parseInt(field.value);
   if (isNaN(tmpval) || tmpval == 0) {
      field.value = '';
      return 0;
   } else {
      field.value = tmpval;
      return tmpval;
   }
}