HTML表单javascript总税金 [英] HTML Form javascript sum total taxes

查看:125
本文介绍了HTML表单javascript总税金的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常好的工作表单,几乎所有的工作都正常。但我需要计算和自动填写总税款。这里是代码:

 < table class =tableventa> 
< tr>
< td style =width:200px;>< / td>
< td valign =topstyle =width:900px;>< table class =table900>
< tr>
< td class =header150>默认单价< / td>
< td class =header150>卖出类型< / td>
< td class =header150>套用税金< / td>
< td class =header150>套用折扣?< / td>
< td class =header150>数量< / td>
< / tr>
< tr>
< td class =header150small>< input type =textclass =input140name =netoid =netoreadonly value =1000>< / td>
< td class =header150small>

< select class =select146name =tipoid =tipo>
< option value =简单选择>无发票< / option>
< option value =Boleta>发票1< / option>
< option value =Factura>发票2< / option>
< / select>

< / td>
< td class =header150small>< select class =select146name =ivaid =iva>
< option value =0selected>免税< / option>
< option value =19>是19%< / option>

< / select>< / td>
< td class =header150small>
< select class =select146name =descuentoid =descuento>
< option value =0selected>无折扣< / option>
< option value =2> 2%折扣< / option>
< option value =3> 3%折扣< / option>
< option value =5> 5%折扣< / option>
< option value =8> 8%折扣< / option>
< option value =10> 10%折扣< / option>
< option value =15> 15%折扣< / option>
< option value =20> 20%折扣< / option>
< option value =30> 30%折扣< / option>
< option value =50> 50%折扣< / option>

< / select>
< / td>
< td class =header150small>< input type =textclass =input140name =cantidadid =cantidadvalue =1>< / td>
< / tr>
< tr>
< td class =header150>折后价格< / td>
< td class =header150>每单位税金< / td>
< td class =header150>每单元小计< / td>
< td class =header150>总税额< / td>
< td class =header150>付款总额< / td>
< / tr>
< tr>
< td class =header150small>< input type =textclass =input140name =preciodescid =preciodescreadonly value =1000>< / td>
< td class =header150small>< input type =textclass =input140name =ivaunitarioid =ivaunitarioreadonly value =0>< / td>
< td class =header150small>< input type =textclass =input140name =subtotalid =subtotalreadonly value =1000>< / td>
< td class =header150small>< input type =textclass =input140name =ivatotalid =ivatotalreadonly value =0>< / td>
< td class =header150small>< input type =textclass =input140name =totalid =totalreadonly value =1000>< / td>
< / tr>
< tr>
< td class =header150small>& nbsp;< / td>
< td class =header150small>& nbsp;< / td>
< td class =header150> Invlice Number< / td>
< td class =header150>& nbsp;< / td>
< td class =header150small>& nbsp;< / td>
< / tr>
< tr>
< td class =header150small>& nbsp;< / td>
< td class =header150small>& nbsp;< / td>
< td class =header150small>< input type =textclass =input140name =documentoid =documentovalue =>< / td>
< td class =header150small>< input class =someter150type =resetvalue =Reset>< / td>
< td class =header150small>< input class =someter150type =buttonvalue =立即出售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>

这里是一个演示小提琴

< https://fiddle.jshell.net/v6spxoqv/3/



这里是我需要的图片



税收我认为它被称为ivatotal(它旁边的其他变量):

  var ivatot = document.getElementsByName ( 'ivatotal')[0]; 

在updateInput函数中执行操作之后(在已包含的操作的末尾) :

  ivatot.value = parseFloat(ttaxes.value)* parseFloat(quantity.value); 

函数tipo_cambio:

 函数tipo_cambio(){
var tipo = document.getElementsByName('tipo')[0];
if(tipo.value ==Simple)
taxes.selectedIndex = 0;
else taxes.selectedIndex = 1;
updateInput();

以前的函数必须从这个select中调用:

 < select class =select146name =tipoid =tipoonchange =tipo_cambio()> 


I have a very nice working form and almost everything is working. But I need the total taxes to be calculated and autofilled. Here is the 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 to 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">&nbsp;</td>
        <td class="header150small">&nbsp;</td>
        <td class="header150">Invlice Number</td>
        <td class="header150">&nbsp;</td>
        <td class="header150small">&nbsp;</td>
        </tr>
      <tr>
        <td class="header150small">&nbsp;</td>
        <td class="header150small">&nbsp;</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 is a demo fiddle

https://fiddle.jshell.net/v6spxoqv/3/

And here is a image of what I need

解决方案

I think that would be required to declare the variable "Total Taxes" I think it is called "ivatotal" so (it next to the other variables):

var ivatot   = document.getElementsByName('ivatotal')[0];

After the operation is performed in the "updateInput" function (at the end of operations that already 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 be called from this select:

<select class="select146" name="tipo" id="tipo" onchange="tipo_cambio()">

这篇关于HTML表单javascript总税金的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆