I am using jquery, ajax and php to retrieve data from database. I want to achieve a functionality i.e. When user inputs product code and press TAB Key the data should be filled in textarea. I'm new to ajax n php, I've checked my query in SQL it is working.. Please help me
html
<input type="text" class="form-control col-md-5 detectTab" name="product_code" />
<textarea class="form-control autogrow" id="container" name="desc" rows="3" cols="5" placeholder="Remarks" required></textarea>
Script
<script type="text/javascript">
$(function(){
$("#product_code").keydown(function(e){
if(9 == e.keyCode){
var postlink = 'loaddesc.php';
$.post(postlink).done(function(data){
if(data)
$("#container").val(data);
else
$("#container").val('No Data Received');
}
}
})
})
</script>
loaddesc.php
<?php
include('config.php');
if($_POST['$product_code'] )
{
$product_code=$_POST['product_code'];
$sql=mysqli_query($con, 'SELECT concat(A.PRODUCT_CAT_NAME," - ", B.name," - ", C.PRODUCT_SERIAL_NO," - ",c.product_desc) Product_Details
FROM dms_product_cat A, dms_product_type B, dms_products c WHERE A.product_cat_id = 1 AND B.product_cat_id = A.product_cat_id and B.type_id = c.product_type
and c.product_code = "$product_code"');
while($row=mysqli_fetch_array($sql))
{
$data=$row['Product_Details'];
echo $data;
}
}
?>