php 中的文本框自动填充
我做作业很困难。我正在尝试制作一个销售发票系统,当一个字段的值发生变化时,该系统会自动填充其他字段,而无需重新加载页面。我尝试过使用会话,但效果不佳,因为我需要刷新页面。
我已经成功地使项目描述从我的 sql 中获取数据,它应该提供我选择的项目的单位。有人可以帮助我吗?
这是我的整个代码:
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>
这是我用于搜索的 php 文件:
<?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();
?>
请帮助我..
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..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用与自动完成相同的方式。你必须使用ajax。一旦有人输入订单号,您就可以向您的 php 页面发出 ajax 请求,然后使用响应填充表单数据。
您可以阅读以下文章。我无法编写所有代码,因为它有点长。
http://www.crackajax.net/popform.php
http://www.ibm.com/developerworks/library/x-ajaxxml9/
看来您正在使用jquery。这样你的工作就会更加轻松。
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.