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

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!