-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
32 lines (25 loc) · 1.16 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
document.addEventListener('DOMContentLoaded', function() {
var form = document.getElementById('vat-calculator-form');
var resetButton = document.getElementById('reset-button');
form.addEventListener('submit', function(event) {
event.preventDefault();
var vatRate = parseFloat(document.getElementById('vat-rate').value);
var amountInput = document.getElementById('amount').value;
// Replace comma with period and parse as float
var amount = parseFloat(amountInput.replace(',', '.'));
if (isNaN(amount)) {
alert('Please enter a valid number for the amount.');
return;
}
var vat = (vatRate / 100) * amount;
var total = amount + vat;
document.getElementById('vat').textContent = vat.toFixed(2);
document.getElementById('total').textContent = total.toFixed(2);
document.getElementById('results').style.display = 'block';
});
resetButton.addEventListener('click', function() {
document.getElementById('vat-rate').value = '21';
document.getElementById('amount').value = '';
document.getElementById('results').style.display = 'none';
});
});