-1

我正在尝试创建一个自我提交选择框,每次用户从下拉列表中选择时,都会将其带到一个新页面。目前它没有做任何事情,只是带我到“//website.com/listing/?col=1&brand=”,没有任何 id 将其指向正确的 url。

请问我做错了什么?

<form method="post" action="">
<select onchange="this.form.submit()">
<? foreach($arrayCollection['brands'] as $id => $name):value ?>
    <option value="//website.com/listing/?col=1&brand=<?php echo $id; ?>">
       <?php echo $name; ?>
   </option>
<? endforeach; ?>
</select>
</form>
4

2 回答 2

1

由于您已在 jquery 中标记:

尝试这个:

<script type="text/javascript" src="jquery-1.2.6.pack.js"></script>
    <form method="post" action="">
    <select id="selectDropDown">
    <? 
    $arrayCollection['brands'] = array(0=>'zero',1=>'first',2=>'second',3=>'three',4=>'four');
    foreach($arrayCollection['brands'] as $id => $name):value ?>
        <option value="<?php echo $id; ?>">
           <?php echo $name; ?>
       </option>
    <? endforeach; ?>
    </select>
    </form>
    <script>
    $('#selectDropDown').change(function(){
    window.location= '//website.com/listing/?col=1&brand='+$(this).val();
    });
    </script>
于 2013-01-03T08:59:22.383 回答
0

你可以试试这个:

<form method="post" action="">
<select onchange="this.form.submit()">
<?php foreach($arrayCollection['brands'] as $id => $name):value ?>
//^^^---------------------missed it
    <option value="//website.com/listing/?col=1&brand=<?php echo $id; ?>">
       <?php echo $name; ?>
   </option>
<?php endforeach; ?>
//^^^---------------------missed it
</select>
</form>

可能对 foreach 文档有用:http: //php.net/manual/en/control-structures.foreach.php

于 2013-01-03T08:57:13.777 回答