Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTML表单javascript总税额_Javascript_Html_Forms - Fatal编程技术网

HTML表单javascript总税额

HTML表单javascript总税额,javascript,html,forms,Javascript,Html,Forms,我有一个非常好的工作方式,几乎一切都在工作。但是我需要计算并自动填写总税额。代码如下: <table class="tableventa"> <tr> <td style="width:200px;"></td> <td valign="top" style="width:900px;"><table class="table900"> <tr> <td cl

我有一个非常好的工作方式,几乎一切都在工作。但是我需要计算并自动填写总税额。代码如下:

<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>

默认单价
销售类型
纳税?
申请折扣?
量
无发票
发票1
发票2
免税的
是19%
不打折
2%折扣
3%的折扣
5%的折扣
八折
九折
八五折
八折
七折
半价
折后价格
单位税额
单位小计
税收总额
应付总额
Invlice编号
var taxes=document.getElementsByName('iva')[0];
var折扣=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(“小计”)[0];
var数量=document.getElementsByName('cantidad')[0];
var ttp=document.getElementsByName('total')[0];
函数updateInput(){
price.value=cost.value-(cost.value*(discount.value/100));
ttaxes.value=(price.value*(taxes.value/100));
var总和=parseFloat(price.value)+parseFloat(ttaxes.value);
total.value=固定的总和(0);
ttp.value=固定的总和(0)*数量.value;
}
taxes.addEventListener('change',updateInput);
折扣。addEventListener('change',updateInput);
成本。添加的列表器(“变更”,更新输入);
成本。添加的监听器('keyup',updateInput);
数量。addEventListener('keyup',updateInput);
这是一把小提琴的演示

这是我需要的图像


我认为需要声明变量“总税收”,我认为它被称为“ivatotal”(它位于其他变量旁边):

在“updateInput”函数中执行操作后(在已包含的操作结束时):

功能“tipo_cambio”:

必须从此选择调用上一个函数:

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

您没有在Javascript代码中设置Total字段的值

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

无法看到您的小提琴和图像,此处提供的小提琴链接现在正常,仍然无法看到图像我不知道为什么不工作,但功能已完成,所有功能都在工作,但不是每个单位*数量的总税额,因此它可以计算总税额。请您编写代码,满足您的需要,如果您遇到困难,我们可以帮助您,而不是要求您完成:)。我看不到您在哪里更新该字段;您更新了
ivaunitario
,但对
ivatotal
不做任何操作。我想这会更好
var ivatot=document.getElementById('ivatotal').Acabo de Realizar la respuesta,al final aparece la función。Por cierto,quéte Pareceria eliminar algunos comentarios innecesarios,para que no se acumulen muchos.更新了代码,选择表单自动更改可以工作,但如果我选择boleta或factura,IVA更改为19%,它只在选择菜单上工作,但不会将IVA应用于输入单。只有onchange可以工作,但不能自动填充ivaActualizada la respuesta。今天我们要做的是“更新输入”最后一个“信息”,这是我们的反应和应用。
function tipo_cambio () {
var tipo = document.getElementsByName('tipo')[0];
if ( tipo.value == "Simple" )
     taxes.selectedIndex = 0;
else taxes.selectedIndex = 1;
updateInput();
}
<select class="select146" name="tipo" id="tipo" onchange="tipo_cambio()">
ivatot.value = (ttaxes.value * quantity.value);