php - 如何实现依赖输入字段的Jquery?

标签 php jquery html ajax mysqli

我正在构建一个发票系统,其中从数据库中检索项目名称和价格。价格取决于项目名称。

现在我必须这样做。

Price: <Input type="text" id="price" name="price" />
Qty : <Input type="text" id="qty" name="qty" />
Tax : <Input type="text" id="tax" name="tax" />
Discount : <Input type="text" id="disc" name="disc" />
Total : <Input type="text" id="total" name="total"  value=" echo $total;"/>

我想自动填充总输入字段而无需使用以下公式重新加载

<?Php 
$total = $price * $qty + $tax - $disc;
?>

最佳答案

需要在您的 html 和一些 jquery 脚本中分配类,

//Assign Amount class in your 4 html fields

    Price: <Input type="text" id="price" name="price" class="amount" />
    Qty : <Input type="text" id="qty" name="qty" class="amount"/>
    Tax : <Input type="text" id="tax" name="tax" class="amount"/>
    Discount : <Input type="text" id="disc" name="disc" class="amount"/>
    Total : <Input type="text" id="total" name="total"  value=" echo $total;"/>

    $( document ).ready(function() {
        $('input.amount').keyup(function(){   
        var price = $("#price").val();
        var qty = $("#qty").val();
        var tax = $("#tax").val();
        var disc = $("#disc").val();
        var total = $("#total").val();
        total = ((parseFloat(price) * parseFloat(qty) + parseFloat(tax) - parseFloat(disc);
        $("#total").val(parseFloat(total));
       });
    });

关于php - 如何实现依赖输入字段的Jquery?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45707587/

相关文章:

php - 使用差异/补丁合并 PHP 更改

php - 使用匿名函数初始化类属性

java - 在ajax调用中没有获得成功响应,每次都进入错误函数

html - 使用搜索和下拉按钮实现导航栏?

python - Django-ckeditor 无法在 html 中正确显示

php - 安全密码生成和存储

phpMyAdmin 错误调用未定义的函数

javascript - 在 jQuery 中重新排列列表元素

javascript - 计算输入的日期和时间之间的差异?

html - 如何让特定的单词变成不同的颜色?