Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const form = document.getElementById('creditForm');
+ const tauxContainer = document.getElementById('tauxContainer');
+ const resultsBody = document.querySelector('#results tbody');
+
+ // Add taux input
+ document.getElementById('addTaux').addEventListener('click', function() {
+ const div = document.createElement('div');
+ div.className = 'tauxInput';
+ div.innerHTML = `
+
+ ×
+ `;
+ tauxContainer.appendChild(div);
+
+ // Remove taux input
+ div.querySelector('.removeTaux').addEventListener('click', function() {
+ div.remove();
+ });
+ });
+
+ form.addEventListener('submit', function(e) {
+ e.preventDefault();
+
+ const prixBien = parseFloat(document.getElementById('prixBien').value);
+ const apport = parseFloat(document.getElementById('apport').value);
+ const duree = parseInt(document.getElementById('duree').value);
+ const tauxInputs = document.querySelectorAll('.taux');
+
+ // Clear previous results
+ resultsBody.innerHTML = '';
+
+ tauxInputs.forEach(input => {
+ const taux = parseFloat(input.value) / 100;
+ const montantEmprunte = prixBien - apport;
+ const fraisNotaire = prixBien * 0.08; // 8% estimation
+
+ // Calculate monthly payment
+ const tauxMensuel = taux / 12;
+ const nbMensualites = duree * 12;
+ const mensualite = (montantEmprunte * tauxMensuel) / (1 - Math.pow(1 + tauxMensuel, -nbMensualites));
+
+ // Calculate total interest
+ const totalInteret = (mensualite * nbMensualites) - montantEmprunte;
+
+ // Calculate total cost
+ const total = montantEmprunte + totalInteret + fraisNotaire;
+
+ // Format numbers
+ const format = num => new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' }).format(num);
+
+ // Add result to table
+ const row = document.createElement('tr');
+ row.innerHTML = `
+
${(taux * 100).toFixed(2)}% +
${format(mensualite)} +
${format(totalInteret)} +
${format(fraisNotaire)} +
${format(total)} + `;
+ resultsBody.appendChild(row);
+ });
+ });
+ });