-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
71 lines (70 loc) · 1.96 KB
/
index.html
File metadata and controls
71 lines (70 loc) · 1.96 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Momsuträknare</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0 auto;
width: 240px;
}
legend {
display: block;
margin-bottom: 10px;
}
legend > div {
display: inline-block;
width: 100px;
font-weight: bold;
margin-bottom: 5px;
}
input {
width: 100px;
padding: 5px;
margin-left: 10px;
text-align: right;
}
input:focus {
font-weight: bold;
}
</style>
</head>
<body>
<form>
<legend><div>Brutto</div>
<input id="brutto" type="number" placeholder="125">
</legend>
<legend><div>Netto</div>
<input id="netto" type="number" placeholder="100">
</legend>
<legend><div>Moms</div>
<input id="moms" type="number" placeholder="25">
</legend>
</form>
<script>
const momsSats = 1.25;
const brutto = document.getElementById("brutto");
const netto = document.getElementById("netto");
const moms = document.getElementById("moms");
[ brutto, netto, moms].forEach((input) => {
input.addEventListener("input", () => {
const b = parseFloat(brutto.value) || 0;
const n = parseFloat(netto.value) || 0;
const m = parseFloat(moms.value) || 0;
if (input === brutto) {
netto.value = (b / momsSats).toFixed(2);
moms.value = Math.abs(b - netto.value).toFixed(2);
} else if (input === netto) {
brutto.value = (n * momsSats).toFixed(2);
moms.value = (brutto.value - n).toFixed(2);
} else if (input === moms) {
brutto.value = (m / (1 - (1 / momsSats))).toFixed(2);
netto.value = (brutto.value - m).toFixed(2);
}
});
});
</script>
</body>
</html>