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

报告相同问题?