-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
98 lines (88 loc) · 2.92 KB
/
index.html
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>EMI Calculator</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<!-- background animations -->
<div class="area">
<ul class="circles">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
<!-- main form and logics -->
<div class="foreground">
<h1>EMI Calculator</h1>
<form id="loanForm">
<label for="total">Enter Total Amount</label>
<input type="number" id="total" step="0.01" required /><br />
<label for="dpp">Enter Downpayment Percent</label>
<input type="number" id="dpp" max="100" required /><br />
<label for="interval">Enter Interval (in months)</label>
<input type="number" id="interval" required /><br />
<label for="interestRate">Enter Interest Rate</label>
<input
type="number"
id="interestRate"
step="0.01"
max="100"
required
/><br />
<!-- <input type="button" value="Submit" onclick="calculateLoan()" /> -->
<input type="button" value="Submit" onclick="calculateLoan()" />
</form>
<div id="results" class="results">
<table>
<tr>
<th>Down payment amount</th>
<td><span id="dpa"></span></td>
</tr>
<tr>
<th>Amount to be paid monthly</th>
<td><span id="monthlyPayment"></span></td>
</tr>
<tr>
<th>Total Balance Remaining</th>
<td>
<span id="amountRemaining"></span> (Interest Rate added on
Remaining Amount)
</td>
</tr>
</table>
</div>
</div>
<script>
function calculateLoan() {
const total = parseFloat(document.getElementById("total").value);
const dpp = parseInt(document.getElementById("dpp").value);
const interval = parseInt(document.getElementById("interval").value);
const interestRate = parseFloat(
document.getElementById("interestRate").value
);
const dpa = (total * dpp) / 100;
const interestAmount = (total - dpa) * (interestRate / 100);
const amountRemaining = total - dpa + interestAmount;
const monthlyPayment = amountRemaining / interval;
document.getElementById("dpa").textContent = dpa.toFixed(2);
document.getElementById("monthlyPayment").textContent =
monthlyPayment.toFixed(2);
document.getElementById("amountRemaining").textContent =
amountRemaining.toFixed(2);
// Show the results
document.getElementById("results").style.display = "block";
}
</script>
</body>
</html>