提交后突出显示表单上的多个选择

时间:2012-05-20 14:37:26

标签: php jquery html post get

下面的这个选择框会在提交表单后记住并突出显示-one-选择。但是,当我将其设为多个时,它在提交后不会突出显示任何选项。 有关如何实现这一点的任何想法?

提前致谢。

<?php
$options_amount = array("0","1","2","3","4","5","6","7","8","9","10+");
$no_way = $_GET['no_way'];
?>

<select class="postform" name="no_way[]" multiple size="5">
<option <?php if ($no_way == 'all') { ?>selected="selected"<?php }?> value="all">Any</option>
<?php
foreach ($options_amount as $option) {
?><option <?php if ($no_way == $option) { ?>selected="selected"<?php }?> value="<?php echo $option; ?>"><?php echo $option; ?></option><?php }?>
</select>

3 个答案:

答案 0 :(得分:2)

$_GET['no_way']仅处理您必须使用$_GET['no_way[]']in_array($option, $no_way)

的单个参数

答案 1 :(得分:0)

我不确定这是否有帮助,但您是否有可能尝试使用selected代替selected="selected"

<option <?php if ($no_way == $option) { ?> selected<?php }?> value="<?php echo $option; ?>"><?php echo $option; ?></option>

答案 2 :(得分:0)

这对我有用:

<?php
$options_amount = array("0","1","2","3","4","5","6","7","8","9","10+");
$no_way = $_GET['no_way'];
?>
<select class="postform" name="no_way[]" multiple size="5">
<option <?php if (in_array("all",$no_way)) { ?>selected="selected"<?php }?> value="all">Any</option>
<?php
foreach ($options_amount as $option) {
?><option <?php if (in_array($option,$no_way)) { ?>selected="selected"<?php }?> value="<?php echo $option; ?>"><?php echo $option; ?></option><?php }?>
</select>