获取所有多个列表框值 [英] Get all multiple listbox values

查看:63
本文介绍了获取所有多个列表框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多选列表框,我在其中使用javascript插入项目。在某一点上,我需要获取所有条目的值(选中和未选中)。
我目前正在使用此代码:

I have a multiple selection listbox in which I insert items using javascript. At a certain point I need to get the values of all entries (both selected and unselected). I'm currently using this code:

<form method="post" action="?page=test" name="something">
<select name="thelist[]" id="selOriginalWindow" size="5" multiple="multiple">
</select>
<input type="button" value="Добави" onclick="openInNewWindow();" />
<input type="submit" value="Get" />
</form>

    <?
if ($_GET['page']=="test") {
    $thelist=$_POST['thelist'];
    var_dump($thelist);
}   
    ?>

Javascript插入值,但PHP只获取所选项的值。如何获取该列表框中所有项目的值?

Javascript inserts the values, but PHP only gets the selected items' value. How do I get the value of all of the items in that listbox?

推荐答案

这就是诀窍:

function selectAll(selectBox,selectAll) {
    if (typeof selectBox == "string") {
        selectBox = document.getElementById(selectBox);
    }
    if (selectBox.type == "select-multiple") {
        for (var i = 0; i < selectBox.options.length; i++) {
            selectBox.options[i].selected = selectAll;
        }
    }
}
</script>
<form method="post" action="?page=test" name="something">
<select name="thelist[]" id="selOriginalWindow" size="5" multiple="multiple">
</select>
<input type="button" value="Добави" onclick="openInNewWindow();" />
<input type="submit" value="Get" onclick="selectAll('selOriginalWindow',true)" />
</form>

    <?
if ($_GET['page']=="test") {
    $thelist=$_POST['thelist'];
    var_dump($thelist);
}   
    ?>

这篇关于获取所有多个列表框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆