I have two input fields. One is to search auto suggest product names using jquery.autocomplete, and in my database I have column name product left
, and I want to display it in the second input, is that possible?
For example: I have a product called apple
with product left
of 30
. apple
will display in the first input field after typing, and at same time 30
must appear in the second field
.
<form action="sales.php" method="post">
<input name="productlist" type="text" id="productlist" size="20"/>
<input name="productleft" type="text" value=""/>
</form>
call jquery ui
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<script>
$(document).ready(function(){
$("#productlist").autocomplete("psuggest.php", {
selectFirst: true
});
});
</script>
inside psuggest.php
<?php
$q=$_GET['q'];
$my_data=mysql_real_escape_string($q);
$mysqli=mysqli_connect('localhost','root','','saganatracker') or die("Database Error");
$sql="SELECT pdesc FROM products WHERE pdesc LIKE '%$my_data%' ORDER BY pdesc";
$result = mysqli_query($mysqli,$sql) or die(mysqli_error());
if($result)
{
while($row=mysqli_fetch_array($result))
{
echo $row['pdesc']."
";
}
}
?>