JavaScript在屏幕上显示所选项目

时间:2017-03-09 19:52:55

标签: javascript php select get

我正在尝试echo来自此多选屏幕的所选结果。但是我的语法不是echo屏幕上的数据。

应该更改哪些内容才能正确显示所选值?

<select name="dothis" size="15" multiple="multiple" tabindex="1">
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
<option value="four">four</option>

foreach ($_GET['dothis'] as $selectedOption)
    echo $selectedOption."\n";

1 个答案:

答案 0 :(得分:0)

这是回显所选选项的方式:

                    <select name="dothis" size="15" multiple="multiple" tabindex="1">
    <option <?php if (isset($_GET['dothis']) == "one") { echo "selected "; } ?>value="one">one</option>
    <option <?php if (isset($_GET['dothis']) == "two") {
            echo "selected ";
        } elseif (!isset($_GET['dothis'])) {
            echo "selected ";
        }?>value="two">two</option>
    <option <?php if (isset($_GET['dothis']) == "three") { echo "selected "; } ?>value="three">three</option>
    <option <?php if (isset($_GET['dothis']) == "four") {
            echo "selected ";
        } elseif (!isset($_GET['dothis'])) {
            echo "selected ";
        }?>value="four">four</option>
    <?php
    foreach ($_GET['dothis'] as $selectedOption)
        echo $selectedOption."\n";