/ Published in: JavaScript
<p>
<p><b>VAT rate:</b>
<p><b>Net price:</b>
<p><b>Gross price:</b>
<p><b>Tax amount:</b>
</p>
<p><b>VAT rate:</b>
<p><b>Net price:</b>
<p><b>Gross price:</b>
<p><b>Tax amount:</b>
</p>
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function net_change() { var vat_rate = document.getElementById('vat_rate'); var net_price = document.getElementById('net_price'); var gross_price = document.getElementById('gross_price'); var tax_amount = document.getElementById('tax_amount'); gross_price.value = net_price.value *(1+(vat_rate.value/100)); tax_amount.value = gross_price.value - net_price.value; } function gross_change() { var vat_rate = document.getElementById('vat_rate'); var net_price = document.getElementById('net_price'); var gross_price = document.getElementById('gross_price'); var tax_amount = document.getElementById('tax_amount'); net_price.value = gross_price.value - (gross_price.value * (vat_rate.value/100)); tax_amount.value = gross_price.value - net_price.value; } function amount_change() { var vat_rate = document.getElementById('vat_rate'); var net_price = document.getElementById('net_price'); var gross_price = document.getElementById('gross_price'); var tax_amount = document.getElementById('tax_amount'); net_price.value = ((tax_amount.value / vat_rate.value)*100); gross_price.value = Number(net_price.value) + Number(tax_amount.value);; } function vat_change() { var vat_rate = document.getElementById('vat_rate'); var net_price = document.getElementById('net_price'); var gross_price = document.getElementById('gross_price'); var tax_amount = document.getElementById('tax_amount'); net_price.value = gross_price.value - (gross_price.value * (vat_rate.value/100)); gross_price.value = net_price.value *(1+(vat_rate.value/100)); } // Добавляет слушателя событий для таблицы var vat_rate = document.getElementById('vat_rate'); var net_price = document.getElementById('net_price'); var gross_price = document.getElementById('gross_price'); var tax_amount = document.getElementById('tax_amount'); vat_rate.addEventListener("input", vat_change, false); net_price.addEventListener("input", net_change, false); gross_price.addEventListener("input", gross_change, false); tax_amount.addEventListener("input", amount_change, false);