dtv995719 2019-02-26 10:55
浏览 39

Javascript / Codeigniter中的价格计算

I want to calculate the Total Price for the order. I got a formula::

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

TotalAmtInclTax = TotalWithoutTax + TotalTax

But I cannot get the output. Please help me and give me some advise on this. Thank You.

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

View:

<!-- **************************** 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/>
  • 写回答

1条回答

  • douhunbei0166 2019-02-26 10:58
    关注
       document.getElementById("totalwithouttax").value=Math.round(totalwithouttax);
    

    this can solve a lot of issues a think

    评论

报告相同问题?

悬赏问题

  • ¥20 fluent无法启动
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。