EKBG EKBG - 5 days ago 6
HTML Question

Text box which populates database value needs to reset when clicks submit button

I have a text box which populates from database value.

<form id="manageSalesForm" name="manageSalesForm" method="post" action="<?php echo BASE_URL?>includes/functions/sales_functions.php">

<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];
?>"/>


I need to reset this, once submit button is clicked. (Moreover, when I clicked the button second time, it clears the text box.

<input type="submit" name="btnProceed" id="btnProceed" value="PROCEED" onclick="document.getElementById('txtSubTotal').value = '';"/>


Proceed button query

<?php

//Start the Session
if(!isset($_SESSION))
{
session_start();
}

include ("/../../pages/sales.php");
include("/../../dbutil.php");

if(isset($_POST['listCustomer'])){ $customer = $_POST['listCustomer'];}
if(isset($_POST['staff'])){ $user = $_POST['staff']; }
if(isset($_POST['txtReceiptNo'])){ $receipt_no = $_POST['txtReceiptNo']; }
if(isset($_POST['txtSubTotal'])){ $subTotal = $_POST['txtSubTotal']; }

if(isset($_POST['btnProceed'])){


$result=mysqli_query($connection,
"INSERT INTO sales(cus_id,item_id,stock_id,receipt_no,qty,unit_price,amount,user_id,purchase_id)
SELECT C.cus_id, I.item_id, S.stock_id, $receipt_no, ST.qty, ST.unit_price, ST.amount, U.id, P.purchase_id
FROM customers C, items I, stock S, sales_temp ST, users U, purchase_items P
WHERE ST.staff='$user'
AND C.customer_name='$customer'
AND I.item_name=ST.item_name
AND S.stock_code=ST.stock_code
AND ST.purchase_id=P.purchase_id");


//Update available qty from purchase_items relevant only to the logged in user(sales_temp table may have records from multiple users)
$resultUpdate=mysqli_query($connection, "UPDATE purchase_items P INNER JOIN sales_temp ST ON (P.purchase_id = ST.purchase_id) SET P.avail_qty = (P.avail_qty - ST.qty) WHERE ST.staff='$user'");

//Delete records relevant only to current user. Here 'WHERE' clause use to prevent deleting other user's records.
$resultDelete=mysqli_query($connection, "DELETE FROM sales_temp WHERE staff='$user'");


if (!$result) {
printf("Errormessage: %s\n", mysqli_error($connection));
}

// use exec() because no results are returned
if ($result) {

/*echo '<script type="text/javascript">',
'salesAddSuccess();',
'</script>';*/
}
else
{
echo '<script type="text/javascript">',
'salesAddFail();',
'</script>';
}}
?>


Code of button
onclick
for displaying the Sub Total,
showSubTotal()


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


This code not works. Please help me.

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