【问题标题】:calculate field value from 2 other fields从其他 2 个字段计算字段值
【发布时间】:2015-10-15 18:44:37
【问题描述】:

我在一个表单中有以下 3 个字段。在retailer_commission 中输入第二个值后,我需要将结果生成到retailer_cog 字段中。 计算是 (price_exec_vat * 零售商佣金)

因为佣金是一个百分比,所以使用以下实际计算 ((price_exc_vat/100)*retailer_commission)

<input name="price_exc_vat" type="number" id="price_exc_vat" placeholder="0.00" min="0" step="0.01" >
<input name="retailer_commission" type="number" id="retailer_commission" placeholder="0" min="0" step="1" >
<input name="retailer_cog" id="retailer_cog" type="text" readonly>

【问题讨论】:

    标签: php jquery key-value


    【解决方案1】:

    您需要将值转换为int。

    这样做:

        $("#retailer_commission").on('keyup',function(){
        var total = parseInt($("#price_exc_vat").val())/100;
        total = total*parseInt($(this).val());
    $("#retailer_cog").val(total);
    });
    

    Fiddle DEMO

    【讨论】:

    • 嗨,Ehsan 非常感谢。我已经更改了代码,但它没有更新和显示带有结果的字段。我正在页面上从 jquery 调用最新的 jquery-latest.pack.js。
    • 检查我在帖子中添加的小提琴
    • 在小提琴中工作正常,但页面没有:) 这就是我所拥有的。我错过了什么吗?在我的原始帖子中添加脚本
    • 确保 jquery 文件路径正确,并在 document.ready 中包装代码
    • 将其保存在文档中。准备好了,这就是我从 jquery src="code.jquery.com/jquery-latest.min.js"> 调用的脚本
    【解决方案2】:

    试试这个

    使用 qty 的值并使用 id retailer_cog

    设置 total
    var qty=$("#retailer_commission");
    qty.keyup(function(){
       var total = ($("#price_exc_vat").val()/100);
       total = (total*qty.val());
       $("#retailer_cog").val(total);
    });
    

    【讨论】:

      【解决方案3】:
      total = ($("#price_exc_vat").val()/100);
      total = (total*qty.val());     //changes in this line
      $("#retailer_cog").val(total);
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-07-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-12
        • 1970-01-01
        • 1970-01-01
        • 2017-10-12
        相关资源
        最近更新 更多