简体   繁体   English

从html表单中获取选择的值列表

[英]get list of values in a select from post html form

This is my form: 这是我的表格:

    <form action="script.php" method="post">
    <SELECT id="avail" name="avail[]" size=5>                                       
           <option value="Avocado">Avocado</option>                                     
           <option value="Bacon">Bacon</option>
           <option value="Black pepper">Black pepper</option>
    </select>
    </form>

How can I get the values available in the select menu from script.php ??? 如何从script.php的选择菜单中获得可用的值?

$_POST["avail"] doesn't work. $_POST["avail"]不起作用。

Thanks 谢谢

$_POST['avail'][0] will contain the select's value the way you have it. $_POST['avail'][0]将以您拥有的方式包含选择的值。 You are using an array by specifying name='avail[]' in the select. 您通过在选择中指定name='avail[]'来使用数组。 You don't need to do this unless you have multiple selects with the same name. 除非您有多个具有相同名称的选择,否则您不需要这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM