刷新后如何保留在同一选择中
How to retain in the same selection after refresh?
刷新时或提交或删除后,如何在下拉列表中保留相同的选择?
我在下面有这段代码,可以从数据库中选择值。我想在刷新或提交表单或删除记录后,在选择下拉列表中使用相同的值返回。
出价.php
<html>
<head>
<script>
function showUser(str) {
var $txtHint = $('#txtHint');
if (str == "") {
$txtHint.html('');
return;
}
$txtHint.load('bid_list.php?q=' + str)
}
</script>
</head>
<body onload=showUser(str="ALL")>
<?php
$mysqli = new mysqli("localhost", "root", "", "app");
$result = $mysqli->query("SELECT bid FROM procurement WHERE bid LIKE '13-___' OR bid LIKE '1_-___' OR bid LIKE '2_-___' GROUP BY bid ORDER BY bid");
$option = '';
while($row = $result->fetch_assoc())
{
$option .= '<option value = "'.$row['bid'].'">'.$row['bid'].'</option>';
}
?>
<select name="users" onchange="showUser(this.value)" style="overflow:scroll;width:100px;">
<option value="ALL" selected='ALL'>ALL</option>
<?php echo $option; ?>
</select>
<div id="txtHint">
</div>
</body>
</html>
bid_list.php
<?php
$mysqli = new mysqli("localhost", "root", "", "app");
$q = $_GET["q"];
$where = '';
if ( $q != 'ALL' ) {
$where = " WHERE bid='$q' ";
}
$result1 = $mysqli->query("
SELECT bid, item_name, item_description, unit, unit_cost, quantity, supplier, po_number, po_date, counter, SUM(unit_cost*quantity) AS total_amount
FROM procurement
$where
GROUP BY counter ORDER BY bid
");
echo'<table id="tfhover" cellspacing="0" class="tablesorter" style="text-transform:uppercase;">
<thead>
<tr>
<th colspan="3" id="none" style="cursor: default;"></th>
<th title="Item Name">Item Name</th>
<th title="Item Description">Description</th>
<th title="Example : Pc, Pcs, Box and Etc.">Unit</th>
<th title="Item Price">Unit Cost</th>
<th title="Total Item Quantity">QTY</th>
<th title="Total Price">Total Amount</th>
<th title="Name of Supplier">Supplier</th>
<th title="Purchase Order Date">PO Date</th>
<th title="Purchase Order #">PO #</th>
<th id="none" style="cursor: default;"></th>
</tr>
</thead>';
echo'<tbody>';
while($row = $result1->fetch_assoc()){
if($row['bid'] != '')
{
echo'<tr>
<td align="center"><a href="bid.php?de='.$row["counter"].'" onclick="return confirm(''Really want to delete ?'');"><img src="images/del.png" border="0" width="10" height="10" title="Delete"></a></td>
<td align="center"><a class="fancybox" href="edit.php?pn='.$row["counter"].'"><img src="images/edit.png" border="0" width="10" height="10" title="Edit"></a></td>
<td align="center"><a class="fancybox" href="comments.php?pn='.$row["counter"].'"><img src="images/remarks.png" border="0" width="10" height="10" title="Remarks and Notes"></a></td>
<td>'.$row['item_name'].'</td>
<td>'.$row['item_description'].'</td>
<td>'.$row['unit'].'</td>
<td>'.number_format($row['unit_cost'], 2, '.', ',').'</td>
<td>'.$row['quantity'].'</td>
<td>'.number_format($row['total_amount'], 2, '.', ',').'</td>
<td>'.$row['supplier'].'</td>
<td>'.$row['po_date'].'</td>
<td>'.$row['po_number'].'</td>
<td><input name="checkbox[]" type="checkbox" id="checkbox[]" value="'.$row['counter'].'"></td>
</tr>';
}
}
echo "</tbody></table>";
使用 jquery ajax 调用
,并在 ajax 调用成功返回时更新 DOM。 见 http://api.jquery.com/jQuery.ajax/
AJAX可用于与数据库的交互式通信,请查看此处的网站: http://www.w3schools.com/php/php_ajax_database.asp
我相信这就是你所需要的。
相关文章:
- 提交后保留下拉选择的值
- 数据是否等于保留或无法被 jQuery/Sizzle 选择
- jQuery blimp文件上传-上传后保留选择图像行
- 保留动态创建的下拉列表's在事件窗口.history.back()上选择的值-JavaScript
- 保留选项列表以供选择
- Yii - 下拉不会保留更改后选择的值
- 余烬.当用户刷新网站时,保留下拉菜单中的选择
- 如何在更改数据源后保留 UI 网格选择
- 我想使用 javascript 将第一个链接保留为默认选择
- 如何在提交查询后保留选择状态
- 在页面重新加载时保留下拉选择
- 使用jQuery UI的选择菜单保留图片
- 将复选框选择保留在多页分页中
- 选择2个自定义匹配器,但保留带状音调符号
- 刷新后如何保留在同一选择中
- 角度JS从数据中选择菜单,在顶部保留1个项目
- 如何在使用 GetElementById 选择更多值时保留值
- 日期选择器 - 如何在单击提交按钮后保留所选值
- 如何使用主干在浏览器背面保留页面选择
- 更改