EKBG EKBG - 2 days ago 5
HTML Question

Sub Total is not getting the changed value from database to input box

I am trying to get the sub total updated, when adding the items to the database from java-script. But, currently it displays the first amount and not updates when adding items. (But when runs the query from phpMyAdmin it works correctly)

enter image description here

enter image description here

java-script code



function showSubTotal() {
<?php $resultT=mysqli_query($connection, "SELECT SUM(amount) FROM sales_temp");
$rowT = mysqli_fetch_row($resultT);
?>
document.getElementById("txtSubTotal").setAttribute('value','');
document.getElementById("txtSubTotal").setAttribute('value',"<?php echo $rowT[0]; ?>");
}


HTML code



<input name="txtSubTotal" type="text" id="txtSubTotal" size="15" / >

<button type="button" name="btnSave" id="btnSave" onclick="submitdata(); check_qty(); showSubTotal();">ADD</button></td>

Answer

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');
jQuery("#txtSubTotal").val(s);
}

And changed the phpgrid code accordingly.

$opt["loadComplete"] = "function(ids) { do_onload(ids); }";
$grid->set_options($opt);
Comments