<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SIP Calculator</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
<style>
body {
background-color: #f0f0f0;
}
.container {
max-width: 400px;
margin-top: 50px;
padding: 20px;
background-color: #ffffff;
border: 1px solid #ddd;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<div class="container">
<h2 class="text-center">SIP Calculator</h2>
<form id="sip-form">
<div class="mb-3">
<label for="investment-amount" class="form-label">Investment Amount:</label>
<input type="number" class="form-control" id="investment-amount" required>
</div>
<div class="mb-3">
<label for="tenure" class="form-label">Tenure (Years):</label>
<input type="number" class="form-control" id="tenure" required>
</div>
<div class="mb-3">
<label for="interest-rate" class="form-label">Interest Rate (%)</label>
<input type="number" step="0.01" class="form-control" id="interest-rate" required>
</div>
<button type="submit" class="btn btn-primary w-100">Calculate</button>
</form>
<div class="modal fade" id="result-modal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Results</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Total Amount Invested: <span id="total-invested"></span></p>
<p>Total Interest Earned: <span id="total-interest"></span></p>
<p>Maturity Amount: <span id="maturity-amount"></span></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
const form = document.getElementById('sip-form');
form.addEventListener('submit', (e) => {
e.preventDefault();
const investmentAmount = parseFloat(document.getElementById('investment-amount').value);
const tenure = parseFloat(document.getElementById('tenure').value);
const interestRate = parseFloat(document.getElementById('interest-rate').value);
const totalInvested = investmentAmount * tenure * 12;
const totalInterest = calculateInterest(investmentAmount, tenure, interestRate);
const maturityAmount = totalInvested + totalInterest;
document.getElementById('total-invested').innerText = `₹${totalInvested.toFixed(2)}`;
document.getElementById('total-interest').innerText = `₹${totalInterest.toFixed(2)}`;
document.getElementById('maturity-amount').innerText = `₹${maturityAmount.toFixed(2)}`;
const resultModal = new bootstrap.Modal(document.getElementById('result-modal'), { keyboard: false });
resultModal.show();
});
function calculateInterest(investmentAmount, tenure, interestRate) {
let interest = 0;
let balance = 0;
for (let i = 0; i < tenure * 12; i++) {
balance += investmentAmount;
interest += balance * (interestRate / 100 / 12);
}
return interest;
}
</script>
</body>
</html>