简体   繁体   English

基于计算的自动更新字段

[英]Auto-Update Field Based on Calculation

I need some help coding a php calculator.. The Algorithm is a little complicated and I would like for the 3rd "Payment" field to auto-update with the result.. 我需要一些编码php计算器的帮助。该算法有点复杂,我希望第3个"Payment"字段可以自动更新结果。

The math goes like this: **$payment**=SUM(**$balance***0.0435)/12+(**$credit***0.0025)/12 数学是这样的: **$payment**=SUM(**$balance***0.0435)/12+(**$credit***0.0025)/12

(This algorithm outputs a Secured LOC Payment for a Mortgage) (此算法输出抵押的有抵押LOC付款)

So I am needing help calculating the $payment value via php for a web-page. 因此,我需要通过php计算网页的$payment值的帮助。 Also I would like for the $payment field to auto-update with the calculated total.. 另外,我想让$payment字段自动使用计算出的总数进行更新。

Here is a excel document doing exactly what I need to create for the web: http://www.dev.jomilla.net/FNCals/SCFC_Secured%20LOC%20Payment%20Calculator_2013%2005%2023.xlsx 这是一个Excel文档,完全可以满足我为Web创建的需要: http : //www.dev.jomilla.net/FNCals/SCFC_Secured%20LOC%20Payment%20Calculator_2013%2005%2023.xlsx

My Fields are written as 我的字段写为

<form>
<input name="credit" id="credit" type="text" >
<input name="balance" id="balance" type="text" >
<input name="payment" id="payment" class="form-control">
</form>

Please help me calculate and auto-populate the result.. Any help would be greatly appreciated! 请帮助我计算并自动填充结果。任何帮助将不胜感激!

I've tried several different ways but I cant seem to make it work, I know some php and js, but I mostly just do front-end web design.. 我尝试了几种不同的方法,但我似乎无法使其工作,我知道一些php和js,但我主要只是进行前端网页设计。

If it helps, my page can be viewed here .. 如果有帮助,可以在这里查看我的页面..

$("#balance,#credit").blur(function() {
    var b = $("#balance").val();
    var c = $("#credit").val();
    if ('' == b || '' == c) {
        return;
    }
    b *= 0.0435;
    c *= 0.0025;
    b /= 12;
    c /= 12;
    var p = b + c;
    $("#payment").val(p);
});

Note that this can be written in a shorter way, but this is the easiest to understand. 请注意,这可以用更短的方式编写,但这是最容易理解的。 Also note that there is no error checking, so if someone writes "foo" in the credit box it's going to break. 另请注意,这里没有错误检查,因此,如果有人在credit框中输入“ foo”,它将被破坏。

A quick fiddle: http://jsfiddle.net/Q9cYv/ shows that the results match up with your Excel file. 一个快速的提琴: http : //jsfiddle.net/Q9cYv/显示结果与您的Excel文件匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM