Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
function calcVat(form, field, field2, field3, vat) {
var amount = eval(document[form][field].value);
var sum = amount*vat;
var total = pound(amount+sum);
document[form][field2].value=total;
document[form][field3].value=pound(sum);
return false;
}
function pound(num) {
var i,l,d;
var nums;
var ret;
nums = String(Math.round(num*100));
while (nums.length <3) nums = "0" + nums;
l = nums.length-3;
ret = "." + nums.charAt(l+1) + nums.charAt(l+2);
d=0;
for (i=l; i>=0; i--) {
ret = nums.charAt(i) + ret;
d++;
if (d==3 && i>0) {
ret="," + ret;
d=0;
}
}
ret = "ú" + ret;
return ret;
}
<html>
<head>
<title>
VAT Calculator
</title>
<script>
// this function is for getting the calculated sum into currency format
function pound(num) {
var i,l,d;
var nums;
var ret;
nums = String(Math.round(num*100));
while (nums.length <3) nums = "0" + nums;
l = nums.length-3;
ret = "." + nums.charAt(l+1) + nums.charAt(l+2);
d=0;
for (i=l; i>=0; i--) {
ret = nums.charAt(i) + ret;
d++;
if (d==3 && i>0) {
ret="," + ret;
d=0;
}
}
ret = "ú" + ret;
return ret;
}
// this is the calculation function
function calcVat(form, field, field2, field3, vat) {
var amount = eval(document[form][field].value);
var sum = amount*vat;
var total = pound(amount+sum);
document[form][field2].value=total;
document[form][field3].value=pound(sum);
return false;
}
</script>
</head>
<body>
<form name="form" method="post" action="#" onsubmit="return calcVat('form','input','total','tax','0.175')">
<table>
<tr>
<td>Amount :</td>
<td><input type="text" name="input" value=""></td>
</tr>
<tr>
<td>VAT :</td>
<td><input type="text" name="tax" onfocus="blur()"></td>
</tr>
<tr>
<td>Total :</td>
<td><input type="text" name="total" onfocus="blur()"></td>
</tr>
<tr>
<td><input type="submit" value="calculate" onclick="return calcVat('form','input','total','tax','0.175')"></td>
</tr>
</table>
</form>
<body>
</html>