E` chiaro.
Ogni volta che aggiorni uno dei subtotoali, vai a sommare il valore del subtotale trovato con il totale precedente.
Ecco un modo per ovviare:
codice:
function subtotale(n){
// metti i nomi dei campi in una variabile
var f = document.form1;
var q = f.elements["quant"+n];
var p = f.elements["prezzo"+n];
var s = f.elements["subtot"+n];
// controlla se la quantità é un numero intero
if(q.value!=parseInt(q.value)&&q.value!=""){
alert("Inserire un numero intero !");
q.value="";
s.value="";
return false;
}else{
// moltiplica quantità per prezzo
subt = q.value * p.value;
// formatta con due decimali ogni campo subtotale
stringa = new String(Math.round((stringa)*100)/100);
stringa += (stringa.indexOf(".")<0)?'.00':'00';
stringa = stringa.substr(0,stringa.indexOf(".")+3);
s.value=stringa;
// calcola valore totale
var tot = 0;
for(var i=1; i<2; i++) { // al posto di 2 metti l n. max
var sub = f.elements["subtot"+i];
tot += parseFloat(sub);
}
// formatta con due decimali il campo totale
stringatot = new String(Math.round((tot)*100)/100);
stringatot += (stringatot.indexOf(".")<0)?'.00':'00';
stringatot = stringatot.substr(0,stringatot.indexOf(".")+3);
f.totale.value = stringatot;
}
}
Ho tolto la sostituzione del punto con il punto (mi pare un'operazione inutile).