EKBG EKBG - 1 year ago 94
HTML Question

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];

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 == '') {
else {
// AJAX code to submit form.
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)
//refresh/update the sub total value when adding
$("#sub_total_div").load(location.href + " #sub_total_div");

Answer Source

I found the solution, added the do_onload(id) to calculate the total on loadComplete event which is triggered after each refresh (also after delete)

function do_onload(id)
    //alert('Simulating, data on load event')

    var s = $("#list").jqGrid('getCol', 'amount', false, 'sum');

And changed the phpgrid code accordingly.

$opt["loadComplete"] = "function(ids) { do_onload(ids); }";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download