douseda0009 2015-10-28 08:31
浏览 13
已采纳

更新PHP表时动态更新文本框。

In PHP codeigniter, I have an interface to add sales records. I select the item and quantity and enter it to the table below.

At the bottom there is a textbox to hold the total price. So I need to update the text box when I'm adding records to the table. how to do it?

  • 写回答

4条回答 默认 最新

  • duanhuo7441 2015-10-28 09:44
    关注

    you cant do this directly from php try using jquery/javacript

    Procedure to do it from jquery

    In a way that when ever value of the input field is changed call a function which will re calculate the sum of all the fields again

    Say you have a table in html like

    |id|Name       |Price|
    ----------------------
    |1 |Some name  |10   |
    |2 |Some name  |20   |
    |3 |Some name  |30   |
    |4 |Some name  |40   |
    ----------------------
    |  |           |100  |
    

    and and input field some where in a form. Id of that input field = "priceInputField" and Class of each column containing price = "priceValue" and Id of the column containing the total is "totalPrice" so your jquery function would look like

    $("#priceInputField").on("change",function(){
        //Some code to add the new row in the table
        var updatedPrice = 0;
        $(".priceValue").each(function(){
            updatedPrice = updatedPrice + $(this).text;
        })
        $("#totalPrice").text("updatedPrice");
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面