JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="total_devis" />
<button name="click" onclick="calculTotal();">Click!!!</button>
<select id="id_tax">
<option value="0">NingĂşn tax</option>
<option value="1">IVA ES 10% (10.000%)</option>
<option>IVA ES 21% (21.000%)</option>
<option>IVA ES 4% (4.000%)</option>
</select>
JavaScript
function getTax(){
if (false)
return 0;
var taxesArray = ["0","10.000","21.000","4.000",];
var selectedTax = document.getElementById("id_tax");
var taxId = selectedTax.options[selectedTax.selectedIndex].value;
console.log(taxId);
return taxesArray[taxId];
}
function calculTotal (){
var tax = getTax();
console.log("tax: "+tax);
var tot_out_ht = 23;
var tot_ttc = tot_out_ht * ((tax/100) + 1);
console.log("tot_ttc: "+tot_ttc);
var shipp = 6.80;
var total = tot_ttc + shipp >= 0 ? Math.round(total = (tot_ttc + shipp)*100)/100 : 0.00;
document.getElementById("total_devis").value = total;
}