Search code examples
javascriptphpjqueryhtmlphpgrid

Change text box value after deleting phpgrid row


I need to refresh the Sub Total div/text box value after deleting the row of phpgrid (phpgrid.org).

Before Delete:

enter image description here

After deleting the second row:

enter image description here

<div id="sub_total_div">
<input name="txtSubTotal" type="text" id="txtSubTotal" size="15" value="<?php 
$sql=mysqli_query($connection,'select sum(amount) from sales_temp');
$row = mysqli_fetch_array($sql);
echo $row[0];
?>"/>
</div>

Please help me.

Edited code:

function submitdata() {
              var listItemName  = document.getElementById("listItemName").value;
              var listStock = document.getElementById("listStock").value;
              var txtUnitPrice = document.getElementById("txtUnitPrice").value;
              var txtQuantity = document.getElementById("txtQuantity").value;
              var listCustomer = document.getElementById("listCustomer").value;
              var txtReceiptNo = document.getElementById("txtReceiptNo").value;
              var TheDate = document.getElementById("TheDate").value;

              // Returns successful data submission message when the entered information is stored in database.
              var dataString = {listItemName:listItemName, listStock: listStock, txtUnitPrice: txtUnitPrice, txtQuantity: txtQuantity, listCustomer: listCustomer, txtReceiptNo: txtReceiptNo};
              if (listItemName == '' || listStock == ''|| txtUnitPrice == ''|| txtQuantity == ''|| listCustomer == ''|| txtReceiptNo == ''|| TheDate == '') {
              salesitemsAddFail();
              } 
              else {
                         // AJAX code to submit form.
                         $.ajax({
                         type: "POST",
                         url: "/pms/includes/functions/sales_temp_functions.php",
                         data: dataString,
                         cache: false,
                         success: function(html) {    

              //reload the sales datagrid once add the item details to temporary table (sales_temp)
              $('#list').trigger("reloadGrid",[{page:1}]);
                 //window.location.reload();
                 //refresh/update the sub total value when adding
                 $("#sub_total_div").load(location.href + " #sub_total_div");
                         }
                         });
                     }
         }

Solution

  • Create a new php file: Gettotal.php

    $sql=mysqli_query($connection,'select sum(amount) from sales_temp');
    $row = mysqli_fetch_array($sql);
    echo $row[0];
    

    your js code will be:

            submitdata() {
                          var listItemName  = document.getElementById("listItemName").value;
                          var listStock = document.getElementById("listStock").value;
                          var txtUnitPrice = document.getElementById("txtUnitPrice").value;
                          var txtQuantity = document.getElementById("txtQuantity").value;
                          var listCustomer = document.getElementById("listCustomer").value;
                          var txtReceiptNo = document.getElementById("txtReceiptNo").value;
                          var TheDate = document.getElementById("TheDate").value;
    
                          // Returns successful data submission message when the entered information is stored in database.
                          var dataString = {listItemName:listItemName, listStock: listStock, txtUnitPrice: txtUnitPrice, txtQuantity: txtQuantity, listCustomer: listCustomer, txtReceiptNo: txtReceiptNo};
                          if (listItemName == '' || listStock == ''|| txtUnitPrice == ''|| txtQuantity == ''|| listCustomer == ''|| txtReceiptNo == ''|| TheDate == '') {
                          salesitemsAddFail();
                          } 
                          else {
                                     // AJAX code to submit form.
                                     $.ajax({
                                     type: "POST",
                                     url: "/pms/includes/functions/sales_temp_functions.php",
                                     data: dataString,
                                     cache: false,
                                     success: function(html) {  
                                     //reload the sales datagrid once add the item details to temporary table (sales_temp)
                                     $('#list').trigger("reloadGrid",[{page:1}]);  
                                     //Ajax call to get the sub
                                    $("#sub_total_div").load("gettotal.php");
    
                                 }
                               });
                             }
                     }
    

    Note : This is not proper method to go with but in your case this will work