Your submit-button's id is totalcost
and your function gets the element with the id totalcost
:
document.getElementById('totalcost').value = sum.toFixed(2)*1.05;
So you can prevent this by not doing this.
Instead of sum.toFixed(2)*1.05
you should do (sum * 1.05).toFixed(2)
as was commented by PSL.
Instead, update your variable:
sum = (sum * 1.05).toFixed(2);
or create a new variable say total
:
var total = (sum * 1.05).toFixed(2);
or just process it where you output the value:
alert( (sum * 1.05).toFixed(2) );
Extra:
Since you are working with money up to 2 decimal points, I'd like to make you aware of the fact that in javascript 0.1+0.2 is NOT 0.3!
The best way to avoid that is to multiply all numbers by the accuracy you need and devide the final (sub-) result by that precision on output.
So: (52 cents + 18 cents = 70 cents) / 100 = 0.7 (and here you'd use toFixed
so it becomes 0.70 ).