Return to Snippet

Revision: 80856
at April 3, 2020 21:55 by antonykidless


Initial Title
VATulator - online VAT calculator

Initial Description
<p><div id="calc">
<p><b>VAT rate:</b>
<input type="text" id="vat_rate" placeholder="20" size="10" value>
<p><b>Net price:</b>
<input type="text" id="net_price" size="10" value>
<p><b>Gross price:</b>
<input type="text" id="gross_price" size="10" value>
<p><b>Tax amount:</b>
<input type="text" id="tax_amount" size="10" value>
</div></p>

Initial Code
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);

Initial Tags
javascript

Initial Language
JavaScript

Initial URL
https://vatulator.com/