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条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题