Javascript / Codeigniter中的价格计算

问题描述 投票:0回答:1

我想计算订单的总价。我有一个公式::

TotalWithoutTax =(UnitPrice * Quantity)+ Transportation + Premium-Discount

TotalAmtInclTax = TotalWithoutTax + TotalTax

但我无法得到输出。请帮帮我,给我一些建议。谢谢。

使用Javascript:

function calcPrice(qty[], unit_price[], gp[], discount[], totalwithouttax, totaltax, totalamtincltax) {
  var quantity = document.getElementById('qty[]').value;
  var unitPrice = document.getElementById('unit_price[]').value;
  var premium = document.getElementById('gp[]').value;
  var discount = document.getElementById('discount[]').value;
  var transportation = document.getElementById('transportation[]').value;

  var totalwithouttax = (unitPrice * quantity) + premium + transportation - discount;
  document.getElementById(totalwithouttax).value = Math.round(totalwithouttax);
  return true;
  var totalwithouttax = document.getElementById('totalwithouttax').value;
  var totaltax = document.getElementById('totaltax').value;

  var totalamtincltax = totalwithouttax + totaltax;
  document.getElementById(totalamtincltax).value = Math.round(totalamtincltax);
  return true;
}

视图:

<!-- **************************** START OF ITEM LIST 1 ************************   -->
<tr class="item-details">
  <td><span class="rowNumber">1</span></td>
  <td class="">
    <?php
      $options = array(
                       '' => '~Choose An Item~'
                       );
      foreach ($item as $rows){
          $options[$rows->id] = $rows->item_name;
      }

      $select = array(
                      'id' => 'item_name',
                      'class' => 'form-control'
                      );
      echo form_dropdown('item_name[]', $options,set_value('item_name'),$select);
    ?>
  </td>
  <td class=""><input type="number" class="item-qty" name="qty[]" /></td>
  <td><input type="number" name="weight[]" class="weight" /></td>
  <td><input type="number" name="transportation[]" class="transporation" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" /></td>
  <td><input type="text" id="gp[]" name="gp[]" value="" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" /></td>
  <td><input type="text" id="discount[]" name="discount[]" value="" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" /></td>
  <td><input type="text" id="unit_price[]" name="unit_price[]" value="" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" /></td>
  <td align="right">
    <input type="text" id="totalwithouttax" name="totalwithouttax" value="" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" readonly>
  </td>
  <td align="right">
    <input type="text" id="totaltax" name="totaltax" value="" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" readonly>
  </td>
  <td align="right">
    <input type="text" id="totalamtincltax" name="totalamtincltax" value="" onkeyup="calcPrice(qty[],unit_price[],gp[],discount[],totalwithouttax,totaltax,totalamtincltax);" readonly>
  </td>
</tr><br/>
javascript php codeigniter
1个回答
0
投票
   document.getElementById("totalwithouttax").value=Math.round(totalwithouttax);

这可以解决很多问题

© www.soinside.com 2019 - 2024. All rights reserved.