HTML Form javascript sum total taxes -
i have nice working form , working. need total taxes calculated , autofilled. here code:
<table class="tableventa"> <tr> <td style="width:200px;"></td> <td valign="top" style="width:900px;"><table class="table900"> <tr> <td class="header150">default unit price</td> <td class="header150">type of sell</td> <td class="header150">apply taxes?</td> <td class="header150">apply discount?</td> <td class="header150">quantity</td> </tr> <tr> <td class="header150small"><input type="text" class="input140" name="neto" id="neto" readonly value="1000"></td> <td class="header150small"> <select class="select146" name="tipo" id="tipo"> <option value="simple" selected>without invoice</option> <option value="boleta">invoice 1</option> <option value="factura">invoice 2</option> </select> </td> <td class="header150small"><select class="select146" name="iva" id="iva"> <option value="0" selected>tax free</option> <option value="19">yes 19%</option> </select></td> <td class="header150small"> <select class="select146" name="descuento" id="descuento"> <option value="0" selected>no discount</option> <option value="2">2% discount</option> <option value="3">3% discount</option> <option value="5">5% discount</option> <option value="8">8% discount</option> <option value="10">10% discount</option> <option value="15">15% discount</option> <option value="20">20% discount</option> <option value="30">30% discount</option> <option value="50">50% discount</option> </select> </td> <td class="header150small"><input type="text" class="input140" name="cantidad" id="cantidad" value="1"></td> </tr> <tr> <td class="header150">price after discount</td> <td class="header150">tax per unit</td> <td class="header150">subtotal per unit</td> <td class="header150">total taxes</td> <td class="header150">total pay</td> </tr> <tr> <td class="header150small"><input type="text" class="input140" name="preciodesc" id="preciodesc" readonly value="1000"></td> <td class="header150small"><input type="text" class="input140" name="ivaunitario" id="ivaunitario" readonly value="0"></td> <td class="header150small"><input type="text" class="input140" name="subtotal" id="subtotal" readonly value="1000"></td> <td class="header150small"><input type="text" class="input140" name="ivatotal" id="ivatotal" readonly value="0"></td> <td class="header150small"><input type="text" class="input140" name="total" id="total" readonly value="1000"></td> </tr> <tr> <td class="header150small"> </td> <td class="header150small"> </td> <td class="header150">invlice number</td> <td class="header150"> </td> <td class="header150small"> </td> </tr> <tr> <td class="header150small"> </td> <td class="header150small"> </td> <td class="header150small"><input type="text" class="input140" name="documento" id="documento" value=""></td> <td class="header150small"><input class="someter150" type="reset" value="reset"></td> <td class="header150small"><input class="someter150" type="button" value="sell now" onclick="document.productos.submit();"></td> </tr> </table></td> </tr> </table> <script> var taxes = document.getelementsbyname('iva')[0]; var discount = document.getelementsbyname('descuento')[0]; var cost = document.getelementsbyname('neto')[0]; var price = document.getelementsbyname('preciodesc')[0]; var ttaxes = document.getelementsbyname('ivaunitario')[0]; var total = document.getelementsbyname('subtotal')[0]; var quantity = document.getelementsbyname('cantidad')[0]; var ttp = document.getelementsbyname('total')[0]; function updateinput() { price.value = cost.value - (cost.value * (discount.value / 100)); ttaxes.value = (price.value * (taxes.value / 100)); var sum = parsefloat(price.value) + parsefloat(ttaxes.value); total.value = sum.tofixed(0); ttp.value = sum.tofixed(0) * quantity.value; } taxes.addeventlistener('change', updateinput); discount.addeventlistener('change', updateinput); cost.addeventlistener('change', updateinput); cost.addeventlistener('keyup', updateinput); quantity.addeventlistener('keyup', updateinput); </script> </form>
here demo fiddle
https://fiddle.jshell.net/v6spxoqv/3/
and here image of need
i think required declare variable "total taxes" think called "ivatotal" (it next other variables):
var ivatot = document.getelementsbyname('ivatotal')[0];
after operation performed in "updateinput" function (at end of operations contains):
ivatot.value = parsefloat(ttaxes.value) * parsefloat(quantity.value);
function "tipo_cambio" :
function tipo_cambio () { var tipo = document.getelementsbyname('tipo')[0]; if ( tipo.value == "simple" ) taxes.selectedindex = 0; else taxes.selectedindex = 1; updateinput(); }
previous function must called select:
<select class="select146" name="tipo" id="tipo" onchange="tipo_cambio()">
Comments
Post a Comment