I'm a student and struggling to get my javascript to add the VAT to the other 'variable'
can somebody please assist - the vat displays as "0"
function calculateTotal(){
var total = 0;
var vat = total*0.14;
for (var k = 0; k < document.forms.service.length; k++)
{
if(document.forms.service.elements[k].checked){
total+=Number(document.forms.service.elements[k].value);
}
}
document.getElementById("total").innerHTML= "The total is R " + total;
document.getElementById("vat").innerHTML= "The total VAT is R " + vat;
}
Move var vat = total*0.14; to the end of the function. You have to calculate the vat after you calculate the total.
function calculateTotal(){
var total = 0;
for (var k = 0; k < document.forms.service.length; k++)
{
if(document.forms.service.elements[k].checked){
total+=Number(document.forms.service.elements[k].value);
}
}
var vat = total*0.14;
document.getElementById("total").innerHTML= "The total is R " + total;
document.getElementById("vat").innerHTML= "The total VAT is R " + vat;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With