下面是我填充动态列表的代码。
<?php
if(isSet($_POST['supplier'])) {
include 'db.php';
$stmt = $mysql->prepare("SELECT DISTINCT SupplierBrand FROM plastic WHERE HeadingNo='".$_POST['supplier']."' ORDER BY SupplierBrand");
$stmt->execute();
$stmt->bind_result($supplierBrand);
?>
<option value="All" width="100px">--ALL--</option>
<?php
while ($row = $stmt->fetch()) : ?>
<option value="<?php echo $supplierBrand; if($_POST['county'] == $supplierBrand) {echo "selected";} ?>" width="100px"><?php echo $supplierBrand; ?></option>
<?php endwhile; ?>
<?php } ?>
我添加了代码
if($_POST['county'] == $supplierBrand) {echo "selected";}
以尝试保留我在提交时选择的值。此上下文中的此代码不起作用。调试后我注意到县值是未定义的。这是 chrome 调试的错误:
Notice</b>: Undefined index: county
如何获取其在另一个页面上的值县,以及$_POST['supplier']
通过使用 jquery 传递上述 php 脚本值。
下面是html代码:
<div id="county_drop_down">
<select id="county" name="county" >
<option value="" width="100px">Supplier...</option>
</select>
</div>
<span id="loading_county_drop_down">
<img src="css/loader.gif" width="16" height="16" align="absmiddle"> Loading...</span>
<div id="no_county_drop_down">No lens type/design has been selected.</div>
对于 javascript,请参阅此链接