Hey all I am trying to update this code I have. It pretty much does what I need it to except one thing. Well two technically, but mostly one I am concerned with. When I check off the boxes I want, it adds up like it is supposed to and adds 5% on top like its supposed to, however it puts the answer in the value of my submit button. How can I stop this from happening? Second (and less important for now) How can I make that total value return as a dollar amount with only 2 decimal points, so instead of returning 0.924 it returns $.92 for example. Thanks!
<body>
<h1> The Fruit Form</h1>
<form action="" name="form1" id="form1">
<input type="checkbox" id='fruit0' value=".59" >Apples ( .59)<br>
<input type="checkbox" id='fruit1' value=".49">Oranges (.49)<br>
<input type="checkbox" id='fruit2' value=".39">Bananas(.39)<br>
<input type="submit" onclick="UpdateCost()" id="totalcost" value="Submit">
</form>
<script type="text/javascript">
function UpdateCost() {
var sum = 0;
var fid, elem;
for (i=0; i<3; i++) {
fid = 'fruit'+i;
elem = document.getElementById(fid);
if (elem.checked == true) { sum += Number(elem.value); }
}
document.getElementById('totalcost').value = sum.toFixed(2)*1.05;
alert("Your Total Is:" + totalcost.value);
return false
}
</script>
</body>