我正在尝试创建一个自提交选择框,每次从下拉列表中选择时,都会将用户带到新页面。目前它没有做太多任何事情,只需带我到“//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>
答案 0 :(得分: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>
答案 1 :(得分: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 doc有用:http://php.net/manual/en/control-structures.foreach.php