I am having a hard time in making my homework. I am trying to make a sales invoice system that automatically fills the other fields when one field's value changes without reloading the page. I've tried using sessions but its not working well because I need to refresh the page.
I've successfully made the item description fetch data from my sql and it should provide the unit of the item I chose. can anybody help me?
here is my whole code:
function suggestValues() {
$("#field").autocomplete("suggestions.php", {
width: 256,
selectFirst: false
});
}
$(document).ready(function(){
suggestValues();
});
<body>
<form name="search" method="post" action="enter_sales2.php">
<table>
<tr>
<td> Receipt #: </td>
<td> <input type="text" size="20" maxlength="15" name="receiptNum"> </td>
</tr>
<tr>
<td> Customer Name: </td>
<td> <input type="text" size="20" maxlength="50" name="customerName"> </td>
</tr>
</table>
<table>
<tr align="center">
<td>Qty</td>
<td> Item Description </td>
<td> Unit </td>
<td> Amount </td>
<td> Total </td>
</tr>
<tr>
<td> <input type="text" size="5" name="qty1"> </td>
<td> <input type="text" size="39" name="item1" id="field" /> </td>
<td> <input type="text" size="5" name="unit1"> </td>
<td> <input type="text" size="5" name="amt1"> </td>
<td> <input type="type" size="8" name="total1"> </td>
</tr>
</table>
and here is my php file for the search:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("consteel", $con);
function autosuggest() {
$q = strtolower($_GET["q"]);
$results = mysql_query("SELECT *FROM item WHERE item_name LIKE '%$q%' LIMIT 10");
while($result=mysql_fetch_assoc($results)){
$item_name = $result['item_name'];
if (strpos(strtolower($item_name), $q) !== false) {
echo "$item_name\n";
}
}
}
autosuggest();
?>
please help me in this..
Use the same way you have used for autocomplete. You have to use ajax. Once someone enter the order number you can make a ajax request to your php page and then populate form data using the response.
You may read following articles. I can't write all the code since it's bit lengthy.
http://www.crackajax.net/popform.php
http://www.ibm.com/developerworks/library/x-ajaxxml9/
Seems you are using jquery. So your work will be more easy.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.