I am trying to display a loading.png graphic in the very short time it takes to do my query e.t.c Everything below works perfectly currently. I just need to get the graphic loading in the td.available only when the productcode has been entered and is being checked.
Any ideas?
Here is my JS
$("#prodcodecheck").blur(function() {
var $this = $(this);
$this
.closest('tr') // find the parent tr
.find('td.available') // find the imgsample in the row
.html( $(this).attr('id')) // update the contents
//.animate({'opacity':1},200);
var available = $this.closest('tr').find('td.available')
$.post('checkstock.php', //this page reads the image code and gives you the image location
{ action: 'searchimage', productcode: $(this).val() },
function(data) {available.html(data);}
);
});
And here is checkstock.php
//Find Stock Value
function checkstock($prodCode) {
$prodCode = strtoupper($prodCode);
require '../../../../config.php';
$dbh = new PDO(DB_DSN, DB_USER, DB_PASS);
$sql = "SELECT * FROM isproducts WHERE prodCode = '".$prodCode."'";
$stmt = $dbh->query($sql);
$obj = $stmt->fetch(PDO::FETCH_OBJ);
$count = $stmt->rowCount();
echo ($count == 1 ? 'The current stock value of item '.$obj->prodCode.' is '.ROUND($obj->FreeStockQuantity, 0).'' : 'Invalid product code');
}
//Call Stock Function
checkstock($_POST['productcode']);