1

我需要一个示例,可以让我在选择第一个下拉列表后填充第二个、第三个、...、第七个下拉列表(所有相同的条目)。我在 HTML 头之前将所有值存储在 PHP 中的数组中。

我查看了一些示例,但找不到具体的解决方案

例如:假设我有一个仓库,里面装满了上述加盟商下的加盟商和网点,我需要为具有 n 个网点的特定加盟商提前 7 天创建订单列表。我的解决方案是用户/仓库运营商选择一个特许经营商,然后第二个(最多 7 个)下拉列表将包含该特许经营商下的网点。

谢谢。


<?php
$productClass = new product();
$productClass->setProductList();

$franchiseeClass = new users();
$franchiseeClass->getAndSetAllFranchisees();
$franchiseeArray = $franchiseeClass->getUserList();

$operatorOutletClass = new users();
$operatorOutletClass->getAndSetUserByLevel("5");

?>

<html><head></head><body>

<div align="center">
    <form name="BBOFranchisee" method="post" action="?" onSubmit="return checkSubmit()">
        <table align="center" border="1">
            <tr>
                <td>
                    Franchisee: 
                </td>
                <td colspan="8">
                    <select name="displayFranchisee" size="1" onChange="populateOutlet('findOutletByFranchisee.php?fid='+this.value)">
                        <option label="franchisees" value="0">--Choose Franchisee--</option> 
                        <?php 
                        for($i=0;$i<count($franchiseeArray);$i++)
                        { 
                            foreach($franchiseeArray[$i] as $key => $val)
                            {
                                echo "<option label=\"franchisees\" value=\"$key\">$val</option>\n";
                            }             
                        } ?>
                    </select>
                </td>
            </tr>
<tr>
                <?php for($j=0;$j<7;$j++) { ?>
                <td>
                    Outlet:
                    <select name="displayOutlet<?php echo $j; ?>" size="1">
                        <option label="outlets" value="0">&nbsp;</option> 
                    </select>
                </td>
                <?php } ?>
            </tr>
</body>
</html>

我想继续是javascript部分..我试图查看http://roshanbh.com.np/2007/12/change-dropdown-list-options-values-from-database-with-ajax-的解决方案and-php.html提供,但它不适用于多个下拉菜单。

4

1 回答 1

0

为了使用该 javascript 示例,您需要在 2nd-7th 选择中添加一个 id -id="displayOutlet<?php echo $j; ?>"

<?php for($j=0;$j<7;$j++) { ?>
      <td>
          Outlet:
          <select name="displayOutlet<?php echo $j; ?>" id="displayOutlet<?php echo $j; ?>"size="1">
               <option label="outlets" value="0">&nbsp;</option> 
          </select>
      </td>
<?php } ?>

然后在您的 javascript 代码中,您可以为 2nd-7th 选择添加一个循环。

if(req.status == 200) { // which represents ok status 
    for(var i=0;i<7;i++){
        document.getElementById('displayOutlet'+i).innerHTML=req.responseText;
    }      
}
于 2013-07-28T04:59:24.350 回答